1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Galina-37 [17]
4 years ago
15

SUMMING THE TRIPLES OF THE EVEN INTEGERS FROM 2 THROUGH 10) Starting with a list containing 1 through 10, use filter, map and su

m to calculate the total of the triples of the even integers from 2 through 10. Reimplement your code with list comprehensions rather than filter and map.
Computers and Technology
1 answer:
Anestetic [448]4 years ago
7 0

Answer:

numbers=list(range(1,11)) #creating the list

even_numbers=list(filter(lambda x: x%2==0, numbers)) #filtering out the even numbers using filter()

triples=list(map(lambda x:x*3 ,even_numbers)) #calculating the triples of each even number using map

total_triples=sum(triples) #calculatting the sum

numbers=list(range(1,11)) #creating the list

even_numbers=[x for x in numbers if x%2==0] #filtering out the even numbers using list comprehension

triples=[x*3 for x in even_numbers] #calculating the triples of each even number using list comprehension

total_triples=sum(triples) #calculating the sum.

Explanation:

Go to the page where you are going to write the code, name the file as 1.py, and copy and paste the following code;

numbers=list(range(1,11)) #creating the list

even_numbers=list(filter(lambda x: x%2==0, numbers)) #filtering out the even numbers using filter()

triples=list(map(lambda x:x*3 ,even_numbers)) #calculating the triples of each even number using map

total_triples=sum(triples) #calculatting the sum

numbers=list(range(1,11)) #creating the list

even_numbers=[x for x in numbers if x%2==0] #filtering out the even numbers using list comprehension

triples=[x*3 for x in even_numbers] #calculating the triples of each even number using list comprehension

total_triples=sum(triples) #calculating the sum

You might be interested in
_______ is defined as a state of periodic or chronic impairment detrimental to the individual and society.
aleksandrvk [35]
I believe the answer is addiction. 
8 0
4 years ago
Read 2 more answers
Write a program with total change amount in pennies as an integer input, and output the change using the fewest coins, one coin
Serjik [45]

Answer:

Here is the Python program:

def FewestCoinVals():  # function to output change using fewest coins

 total_change = int(input('Enter change amount in pennies: '))

#prompts user to enter total change amount in pennies

 if total_change <= 0:  # if value of total_change is less or equal to 0

   print('no change')  # prints no change

 else:  # if value of total_change is greater than 0

   dollars = total_change // 100  

#calculate value of dollars by dividing total_change by 100

   total_change %= 100   #take mod of value of total_change with 100

#calculate value of quarters by dividing total_change by 100

   quarters = total_change // 25

   total_change %= 25  #take mod of value of total_change with 25

#calculate value of dimes by dividing total_change by 100

   dimes = total_change // 10  

   total_change %= 10  #take mod of value of total_change with 10

#calculate value of nickels by dividing total_change by 100

   nickels = total_change // 5

   total_change %= 5  #take mod of value of total_change with 5

   pennies = total_change  

#value of pennies is equal to value of total_change

#the if elif statement checks for the singular and plural coin names

   if dollars >1:

       print('dollars: ',dollars)

   elif dollars ==1:

       print('dollar: ',dollars)

   if quarters > 1:

       print('quarters: ',quarters)

   elif quarters ==1:

       print('quarter: ',quarters)

   if dimes >1:

       print('dimes: ',dimes)

   elif dimes ==1:

       print('dime: ',dimes)

   if nickels >1:

       print('nickels: ',nickels)

   elif nickels ==1:

       print('nickel: ',nickels)

   if pennies >1:

       print('pennies: ',pennies)

   elif pennies ==1:

       print('penny: ',pennies)

#calls the FewestCoinVals() function        

FewestCoinVals()

                     

Explanation:

The program prompts the user to enter change amount in pennies and has int() function to convert input value to integer.  If the value entered is less than or equal to 0 it displays message "no change", otherwise it converts the value using fewest coins. The formulas for converting to each type is given in the code. It uses if and elif statements to check if the final value of total_change has singular or plural coin names such as penny or pennies. The program along with output is attached as the screen shot.

3 0
3 years ago
Which method finds the greatest common divisor of 14 and 35?
Liula [17]

Answer:

gcd method

Explanation:

Given

The code snippet

Required

Which method completes the code

To return the gcd of numbers, simply use the gcd method.

So: the complete code is;

<em>import math</em>

<em>math.gcd(14,35)</em>

6 0
3 years ago
What is the output of print str if str = 'Hello World!'? A - Hello World! ... Q 18 - What is the output of print list[1:3] if li
Elenna [48]
Is this some jiberish or is this a different language because I can’t understand nothing you just typed
6 0
3 years ago
What structure in the eye plays a role in accommodation by holding the lens in place?
Neko [114]
<span>The answer is Ciliary body.  It is the </span>structure in the eye that plays a role in accommodation by holding the lens in place.  <span>The </span>ciliary body<span> has 3 </span>functions<span>: 1) accommodation  2) aqueous humor production and resorption                      3) maintenance of the lens zonules for the purpose of securing the lens in place.</span>
7 0
4 years ago
Other questions:
  • Write a program TwoSmallest.java that takes a set of double command-line arguments and prints the smallest and second-smallest n
    5·1 answer
  • What does nntp stand for?
    12·2 answers
  • write an algorithm that gets the price for item A plus the quantity purchased. The algorithm prints the total cost, including a
    5·1 answer
  • A user is connecting to an e-commerce server to buy some widgets for a company. the user connects to the site and notices there
    10·1 answer
  • This is the most flexible way to create a query. Used to create queries that displays only the records that match criteria enter
    12·1 answer
  • Design aPayrollclass that has fields for an employee’sname, ID number, hourly pay rate,and number of hours worked. Write theappr
    9·1 answer
  • Việc áp dụng khai báo hải quan điện tử có áp dụng chữ ký số, đem lại những lợi ích gì
    10·1 answer
  • The Mac OS was the first to use a graphical user interface.<br><br><br> False<br><br> True
    7·1 answer
  • Cui documents must be reviewed to which procedures before destruction?
    13·1 answer
  • Create a plot of monthly averaged max and min temperature (columns TMAX and TMIN). That is each January in the record will be in
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!