Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in bash, PERL, and Python languages that does the following: 5] Write a program

ID: 3718749 • Letter: I

Question

in bash, PERL, and Python languages that does the following: 5] Write a program a. Generates 50 random numbers between -23 and +31. b. Calculates the average of the generated numbers using a function you define. c. Calculates the mode of the generated numbers using a function you define. d. Calculates the sum of the squares of the generated numbers using a function. e. Prints the average, mode, and squared sum values in a single line separated by 1. 17 spaces using a print function that makes call to the previously defined functions. Mode is the number that occurs most frequently Bash code:

Explanation / Answer

Hi,
here is the full code with comments
from random import randint
def average(l):#method for average
return sum(l)/len(l)
def mode(l):# method to get mode
return max(set(l), key=l.count)# counting the most occured
def squares(l):# method to get sum of squares
sum=0
for i in l:
sum=sum+i*i#adding square of each number
return sum
count=0
numbers=[]
while count<50:
numbers.append(randint(-23, 31))#adding each random number to list
count=count+1
print("Average :",average(numbers)," Mode: ",mode(numbers)," Sum of Squares: ",squares(numbers))


Thumbs up if this was helpful, otherwise let me know in comments