So, the assignment is to ask the user for how many randomly generated numbers they want in a list, and then from that list find the: total(sum), the average, the smallest and the largest number. SOFAR, I am getting an error on line 14 "object of type 'int' has no len()". I get the same responce when using < too.
import random
def main():
randomList = 0
smallest = 0
largest = 0
average = int(input("How may numbers (between 1-100) would you like to generate?: "))
total = 0
if average >= 101 or average <= 0:
print("Invalid input:How may numbers (between 1-100) would you like to generate?: ")
else:
while randomList != len(int(average)):
randomList.append(random.randint(1,101))
randomList=sorted(randomList)
print(randomList)
total = sum(randomList)
average = float(sum(randomList)) / max(len(randomList))
largest = randomList.pop(average)
smallest = randomList.pop(0)
print('The total of all the numbers are ',str(total))
print('The average of all the numbers are ',str(average))
print('The largest of all the numbers are ',str(largest))
print('The smallest of all the numbers are ',str(smallest))
main()
Aucun commentaire:
Enregistrer un commentaire