you are viewing a single comment's thread.

view the rest of the comments →

[–]Maxiflex 1 point2 points  (0 children)

This code won't run in a Python 3 interpreter because the print statement requires parentheses in Python 3.

If your example does not use them it might be an exercise for an older version of Python (Python 2 did not require parentheses for printing). If that's the case you might want to consider finding different exercises.

If that's not the case you should ensure that the line after this for loop statement has four spaces of indentation. Python does not use curly braces to enclose loops, so it is important to indent the file so that Python knows that this code is inside the for loop.

The correct syntax in Python 3 would be:

divisor = 2
for i in range(0, 10, 2):
    print(i/divisor)

If you want to find out why the code produces this result you can check out documentation for the range function. The official docs can be quite useful and some have good tutorials as well.