在Python 3.6中检测用户输入的最低值

时间:2017-10-14 19:01:17

标签: python min

我必须根据用户输入计算一组值的平均等级,同时在计算平均值之前降低最低等级。我有除了代码之外的所有内容以删除最低值。我尝试使用min函数,但是当在循环中打印时,我得到" TypeError:' int'对象不可迭代。"知道如何解决这个问题吗?谢谢!

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

1 个答案:

答案 0 :(得分:0)

我已修改您的申请,请参阅下文并尝试了解满足您要求所需的更改。

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