75.4k views
2 votes
Write a method named buildArray that builds an array by appending a given number of random two-digit integers. It should accept two parameters—the first parameter is the array, and the second is an integer for how many random values to add.

Print the array after calling buildArray.

User Jerm
by
4.7k points

1 Answer

2 votes

Answer:

the code using Python

Step-by-step explanation:

import random

def buildArray(array, size):

for i in range(size):

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

def sumArray(array , num):

sum_array = 0

for i in range(num):

sum_array += array[i]

return sum_array

def main():

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

array = []

buildArray(array, n)

print(array)

num = int(input("How many values to find sum of array:\\"))

result= sumArray(array,num)

print(result)

main()

User Rakesh Kalashetti
by
4.7k points