Answer to Question #170139 in Python for John

Question #170139

After your program has prompted the user for how many values should be in the array, generated those values, and printed the whole list, create and call a new function named sumArray. In this method, accept the array as the parameter. Inside, you should sum together all values and then return that value back to the original method call. Finally, print that sum of values.

Sample Run

How many values to add to the array: 
8
[17, 99, 54, 88, 55, 47, 11, 97]
Total 468
1
Expert's answer
2021-03-08T17:03:51-0500
import random


def sumArray(ls):
    lst_sum = 0
    for element in ls:
        lst_sum += element
    return lst_sum


print("How many values to add to the array:")
n = int(input())
lst = []
for i in range(n):
    lst.append(random.randint(0, 100))
print(lst)
sum_array = sumArray(lst)
print('Total ', sum_array)

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