Answer to Question #275554 in Python for Rushkie

Question #275554

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 processin


1
Expert's answer
2021-12-04T20:51:46-0500
import random




def sumList(numbers):
    result=0
    for row in numbers:
        print(row)
        result+=row
    print(f"The sum is: {result}")




def main():
    n=int(input("Enter number of numbers for the list: "))
    if(n>0):
        numbers=[]
        for i in range(0,n):
            numbers.append(random.randint(0,100))
    sumList(numbers)
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