Ask coding questions

← Back to all posts
Why is an int() value not iteratable
Gamarleton

When I use int() to convert an input number string into a number value, the program reads the value as an "int() object" and complains it can't iterate with objects.

I thought int() converted a value into an integer?
Am I missing something on how this works?

Voters
Gamarleton
Comments
hotnewtop
MrVoo

Integers aren't iteratable. Use range(x), which is iteratable

Gamarleton

@MrVoo
Well the range was supposed to be from 0 to chosen number, hence "0-n" on line 7.

How else would I do this?

MrVoo

@Gamarleton That's not how Python works, do for i in range(5) if you want to loop 5 times

Gamarleton

@MrVoo But the task was to return all integers under the input number. Idk what else to do for that :(

MrVoo

@Gamarleton Put the input value inside the range??