为什么我得到Typeerror:'int'对象不可迭代

时间:2015-02-05 22:04:17

标签: python python-3.x

我正在编写一个简短的程序来取十个数字并将它们重新打印为一个列表,但用零替换低于一定数量的数字。首先,'输入'不起作用,并提示我提供数字。其次我得到'TypeError:'int'对象不可迭代'为主函数中的第二个'for'循环。有什么想法吗?

amx = []

def validamount(amount, limit):
    if amount >= limit:
        return amount
    else:
        return 0

def main():
    for i in 10:
        amx.append(int(input()))
    for i in 10:
        print(validamount(amx[i], 5))

main()

2 个答案:

答案 0 :(得分:3)

你不能迭代一个数字,试试:

for i in range(10):

参考: https://docs.python.org/2/library/functions.html#range

答案 1 :(得分:2)

for i in 10:是您错误的来源;它应该是for i in range(10):而已。