user3397243
user3397243

Reputation: 567

Python error for loop

I am very new to programming and Python!

for i in range(0.6):
print(i)

I am getting error:

Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    for i in range(0.6):
TypeError: 'float' object cannot be interpreted as an integer

Upvotes: 1

Views: 89

Answers (3)

Srivatsan
Srivatsan

Reputation: 9363

Range takes in two values, not a single float!

It should be

for i in range(0,6):
    print(i)

this would give you

0
1
2
3
4
5

or just range(6)

Upvotes: 4

wcb98
wcb98

Reputation: 172

You probably mistyped, and meant to put a comma instead of a dot:

for n in range(0,6):
    print(n)

actually, the '0' in range() is not even needed, you can also do this, and it will print the same thing:

for n in range(6):
    print(n)

both would output:

0
1
2
3
4
5

Upvotes: 1

jh314
jh314

Reputation: 27802

You probably meant this:

for i in range(0,6):
    print(i)

You need to change period to comma. Also, you need to indent the print statement.

Upvotes: 3

Related Questions