mistermarko
mistermarko

Reputation: 305

Why am I getting Typeerror: 'int' object not iterable

I'm writing a short program to take ten numbers and reprint them as a list but replacing those below a certain amount with zero. First, 'input' isn't working and prompting me to give the numbers. Second I'm getting 'TypeError: 'int' object not iterable' for the second 'for' loop in the main function. Any ideas?

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()

Upvotes: 1

Views: 557

Answers (2)

taesu
taesu

Reputation: 4580

You cannot iterate over a number, try:

for i in range(10):

refer to: https://docs.python.org/2/library/functions.html#range

Upvotes: 3

jwodder
jwodder

Reputation: 57630

for i in 10: is the source of your error; it should be for i in range(10): instead.

Upvotes: 2

Related Questions