int object is not iterable Error

If your code is like below

count = 100
for number in count:

This will give you error like.. int object is not iterable.

In Python, the thing you pass to a for statement needs to be some kind of iterable object. The variable count here is a number which is not iterable.

You should be writing the code like below to fix the error

for number in range(count):
    # do stuff

In this case, what you want is just add a range statement. This will generate a list of numbers, and iterating through these will allow your for loop to execute the right number of times.

Leave a Reply