我该如何解决:'int' 对象不可迭代

How do I fix : 'int' object is not iterable

我正在尝试 运行 这段代码,但我收到一条错误消息 'int' object is not iterable for line 10。不知道哪里出错了。

def inputVal(prompt,lower,upper):
    print(prompt)
    retVal = int(input())
    while retVal<lower or retVal>upper:
        print('Incorrect Value')
        retVal = int(input())
    return retVal

numComp = inputVal("Please enter number of competitors", 5, 20)

for comp in numComp:
    total=0
    for i in range(5):
        judgescore = inputVal('Please input judges score', 0, 10)
        total = total + judgescore
    print("Total judge score for competitor ", comp+1, "is: ", total)
    print("Average judge score for competitor ", comp+1, "is: ", total/5)

来自这一行:

for comp in numComp:

因为 numComp 是来自用户的 intints 不能迭代(迭代数字没有任何意义)

也许你的意思是:

for comp in range(numComp):