I'm writing a program that adds a random number for each element in a list of names and then divides the result by the length of the list to find the average. I wanted to know how to add a random number for each element in the list and then subsequently store those random numbers in a separate list. thank you!
def averageAssignment(names, assignment):
print("Enter the student names you would like to find the average for")
classlist = []
while True:
names = input("")
if str.lower(names) == 'q':
break
classlist.append(names)
for name in classlist:
print(name)
while 'q' or 'Q' in classlist:
Assignemnt_Number = input(("Enter the Assignment you woudl like to average: "))
if Assignemnt_Number == 0:
for name in classlist:
import random
names = classlist.index(name)
print("The average of assignment #" + Assignemnt_Number + "is: ")
print (random.randint(1,101)*classlist[names])
if Assignemnt_Number == 1:
for name in classlist:
import random
names = classlist.index(name)
print("The average of assignment #" + Assignemnt_Number + "is: ")
print (random.randint(1,101)*classlist[names])
if Assignemnt_Number == 2:
for name in classlist:
import random
names = classlist.index(name)
print("The average of assignment #" + Assignemnt_Number + "is: ")
print (random.randint(1,101)*classlist[names])
if Assignemnt_Number == 3:
for name in classlist:
import random
names = classlist.index(name)
print("The average of assignment #" + Assignemnt_Number + "is: ")
print (random.randint(1,101)*classlist[names])
else:
return -999
averageAssignment(classist, Assignment_Number)
Aucun commentaire:
Enregistrer un commentaire