Как мне исправить: объект 'int' не повторяется - PullRequest
1 голос
/ 10 июня 2019

Я пытаюсь запустить этот фрагмент кода и получаю сообщение об ошибке '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)

1 Ответ

5 голосов
/ 10 июня 2019

Это происходит из этой строки:

for comp in numComp:

Потому что numComp - это int, исходящий от пользователя.И int s не может быть повторен (нет смысла перебирать число)

Возможно, вы имели в виду:

for comp in range(numComp):
...