Answer to Question #214806 in Python for Lia

Question #214806
Write a python function called sumList() which will receive a list of integers as an input parameter. sumList must : print the list, sum all the numbers in a list and print the total. Programs main section must ask the user how many numbers the list should contain and create the list accordingly to contain randomly generated integers between 0 and 10. The list should be passed to sumList() for processing. Example output if the list containing 5 numbers is passed to sumList()
[2,45,78,56,32]
The total is: 213
1
Expert's answer
2021-07-07T18:18:40-0400
import random



def sumList(integers):
    Result=0
    for n in integers:
        print(f"{n}")
        Result+=n
    print(f"The total is: {Result}")



#main section
n=int(input("How many numbers the list should contain? "))
if(n>0):
    integers=[]
    for i in range(0,n):
        integers.append(random.randint(0,10))
sumList(integers)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS