8.6 Code Practice: Question 2
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.

Respuesta :

Answer:

import random

def buildArray():

   amount = int(input("How many values to add to the array: "))

   array = []

   for i in range(amount):

       array.append(random.randint(10, 99))  

   return array

array = buildArray()

print(array)

def sumArray(array):

   return sum(array)

sum_array = sumArray(array)

print("The total is: ", sum_array)

Explanation:

this gave me 80%

In this exercise we have to use the knowledge of computational language in python to write the code.

We have the code in the attached image.

The code in python can be found as:

import random

def buildArray():

  amount = int(input("How many values to add to the array: "))

  array = []

  for i in range(amount):

      array.append(random.randint(10, 99))  

  return array

array = buildArray()

print(array)

def sumArray(array):

  return sum(array)

sum_array = sumArray(array)

print("The total is: ", sum_array)

See more about python at brainly.com/question/26104476

Ver imagen lhmarianateixeira
Ver imagen lhmarianateixeira