Computer Science, asked by gazdon617, 2 months ago

Need help on this lesson in edhesive programming language is pyhton

Attachments:

Answers

Answered by allysia
1

Question:

Write a method named buildArray that builds an array by appending a given number of random two-digit integers(10-99) . It should accept two parameters—the first parameter is the array, and the second is an integer for how many random values to add, which should be input by the user.

Print array after calling buildArray.

Language:

Python

Program:

def buildarray(array, length):

   import random

   for i in range(length):

       array.append(random.rand int(10,99))

   return array

array=eval(input("Enter an array:" ))

length = int(input("Enter the values to add: " ))

buildarray(array,length)

Output:

Enter an array:[1,2,3]  

Enter the values to add: 4

Out[35]: [1, 2, 3, 10, 19, 27, 19]

Explanation:

  • define a function that accepts array and length to add to the older list entered by the user.
  • random function is used to generate random numbers from 10 to 99.

Attachments:

Attachments:
Similar questions