mercredi 23 septembre 2020

print average of a generated list

I'm trying to generate a list of integers length n n is inputted by the user. Then print the smallest and largest number and the average of the list.

I've managed to get it to generate the numbers and print the smallest and largest number. I've tried to divide the list by the items but I'm a bit stuck. I think maybe my logic is off?

e = int(input("enter a num: "))
import random
randomlist = []
for i in range(e):
    n = random.randint(1,101)
    randomlist.append(n)
    avg = randomlist/e
print("generated values:",randomlist)
print (min(randomlist),max(randomlist),avg(randomlist))



Aucun commentaire:

Enregistrer un commentaire