Answer to Question #214737 in Python for Ally

Question #214737

Write a Python function called sumList () which will receive a list of integers as input parameter. sumList() must: a) Print the list b) Sum all the numbers in a list and print the total. The main section of your program must: c) Ask the user how many numbers the list should contain; d) Create the list accordingly (containing randomly generated integers between 0 and 100); e) Pass the list to sumList () for processing. Example output if a list containing four numbers is passed to sumList() [3, 47, 94, 1]. The total is: 145


1
Expert's answer
2021-07-07T06:26:24-0400
import random


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


def main():
    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,100))
    sumList(integers)
main()




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