Find the best answers to your questions at Westonci.ca, where experts and enthusiasts provide accurate, reliable information. Get quick and reliable solutions to your questions from a community of experienced experts on our platform. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.

Copy and paste your code from the previous code practice. If you did not successfully complete it yet, please do that first before completing this code practice.

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.

Sagot :

The code practice illustrates the following concepts:

  • Arrays or Lists
  • Methods or Functions

The program in Python

The program written in Python, where comments are used to explain each action is as follows:

#This imports the random module

import random

#This defines the sumArray method

def sumArray(myList):

   #This initializes the sum to 0

   isum = 0

   #This iterates through the list

   for i in myList:

       #This adds the array elements

       isum+=i

   #This returns the sum

   return isum

#This gets the number of values    

n = int(input("Number of values: "))

#This initializes the list

myList = []

#This iterates from 0 to n - 1

for i in range(n):

   #This populates the list

   myList.append(random.randint(0,100))

#This prints the list

print(myList)

#This calls the sumArray method

print(sumArray(myList))

   

Read more about Python programs at:

https://brainly.com/question/24833629

#SPJ1