我正在写一个简短的程序,取10个数字,并将它们作为一个列表重新打印,但将低于一定数量的数字替换为零。首先,“输入”不起作用,促使我给出数字。第二个是main函数中第二个“for”循环的“TypeError:”int“object not iterable”。有什么想法吗?在
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()
不能对数字进行迭代,请尝试:
参考: https://docs.python.org/2/library/functions.html#range
for i in 10:
是错误的来源;它应该是for i in range(10):
。在相关问题 更多 >
编程相关推荐