Question

1. Define a function in python that returns the sum of the following 4 lists. Remember...

1. Define a function in python that returns the sum of the following 4 lists. Remember to store and re- use your code instead of summing the values for each list 4 times. Hence, define a function that takes as an argument a list and returns the sum of values.

  • Copy the following lists and paste them in a Python file after you define the sum_of_values function

  • Call the function and pass to it a different list each call as an argument

    list1 = [5, 7, 4, 1, 8, 9, 56, 34, 65, 100]
    list2 = [1, 2, 5, 6, 8, 6, 0, 19, 8, 10, 11, 12]
    list3 = [1.1, 1.6, 7.8, 9.4, 6.7, 8.9, 99.7, 65.6, 45.5, 54.5, 12.7] list4 = [10.5, 100.5, 20.5]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is code:

def sum_of_values(list):
sum = 0
for val in list:
sum = sum + val
return round(sum,1) # round value


list1 = [5, 7, 4, 1, 8, 9, 56, 34, 65, 100]
list2 = [1, 2, 5, 6, 8, 6, 0, 19, 8, 10, 11, 12]
list3 = [1.1, 1.6, 7.8, 9.4, 6.7, 8.9, 99.7, 65.6, 45.5, 54.5, 12.7]
list4 = [10.5, 100.5, 20.5]

print("The sum of list1 is : ", sum_of_values(list1))
print("The sum of list2 is : ", sum_of_values(list2))
print("The sum of list3 is : ", sum_of_values(list3))
print("The sum of list4 is : ", sum_of_values(list4))

Output:

Add a comment
Know the answer?
Add Answer to:
1. Define a function in python that returns the sum of the following 4 lists. Remember...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT