I have to calculate the average grade for a set of values based on user input, while dropping the lowest grade before calculating the average. I have everything except for the code to drop the lowest value. I tried using the min function, but when printed inside the loop I get "TypeError: 'int' object is not iterable." Any idea how to fix this? Thanks!
numuser=eval(input("How many users are there?: "))
numgrade=eval(input("How many grades will there be for each user?: "))
usercount=0
gradecount=0
while usercount <= numuser:
name=input("Please enter the user's first and last name: ")
gradetot=0
while gradecount < numgrade:
gradeval=eval(input("Please enter the grade: "))
gradetot=gradetot+gradeval
gradecount=gradecount+1
low = min(gradeval)
tot = gradetot-low
print("The average grade for", name, "is :", tot/gradecount)
numuser=numuser-1
usercount=usercount+1
gradecount=0
I have modified your application please see below and try to understand what change needed to fulfil your requirement.
numuser=eval(input("How many users are there : " ))
numgrade=eval(input("How many grades will there be for each user : " ))
usercount=0
gradecount=0
gradeval = [] # you need a array to store a range of values
while usercount <= numuser:
name=input("Please enter the user's first and last name : " )
gradetot=0
while gradecount < numgrade:
val=eval(input("Please enter the grade : " ))
gradeval.append(val)
gradetot=gradetot+val
gradecount=gradecount+1
low = min(gradeval)# min function need a range of values
tot = gradetot-low
print("The average grade for : ", name, "is : ", tot/gradecount)
numuser=numuser-1
usercount=usercount+1
gradecount=0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.