如何解决:“ int”对象不可迭代

时间:2019-06-10 04:40:08

标签: python object int 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)

1 个答案:

答案 0 :(得分:5)

它来自此行:

+----------------------------------------------------------------------+-------+
| metrics                                                              | value |
+----------------------------------------------------------------------+-------+
| http_requests_total{endpoint="/slow",method="GET",status_code="200"} | 90    |
+----------------------------------------------------------------------+-------+
| http_requests_total{endpoint="/slow",method="GET",status_code="500"} | 10    |
+----------------------------------------------------------------------+-------+

因为+----------------------------------------------------------------------+-------+ | metrics | value | +----------------------------------------------------------------------+-------+ | http_requests_total{endpoint="/slow",method="GET",status_code="200"} | 90 | +----------------------------------------------------------------------+-------+ | http_requests_total{endpoint="/slow",method="GET",status_code="500"} | 10 | +----------------------------------------------------------------------+-------+ | http_requests_total{endpoint="/fast",method="GET",status_code="200"} | 726 | +----------------------------------------------------------------------+-------+ | http_requests_total{endpoint="/fast",method="GET",status_code="500"} | 32 | +------------------------------------------------------------------------+-------+ | http_requests_total{endpoint="/medium",method="GET",status_code="200"} | 90 | +------------------------------------------------------------------------+-------+ | http_requests_total{endpoint="/medium",method="POST",status_code="500"}| 10 | +------------------------------------------------------------------------+-------+ 是来自用户的for comp in numComp: 。而且numComp不能迭代(迭代一个数字没有任何意义)

也许你是说:

int