Newbie, needs help, cant see problem


#1

On step 13 you have to write a simple text, so iw rote somethinng like that:
#Comment hya#
monty = True
python = 1.234
monty_python = python ** 2

It shows me this information: IndentationError: unexpected indent
Did you create a variable called monty?
I tried several times to solve but i cant. maybe its a bug, idk help pls


#2

If your code looks like this,

#Comment hya#
	monty = True
        python = 1.234
        monty_python = python ** 2

Then it is clear there are indentation issues. None of the above is a code block, so should have no indents on any lines.


#3

So when should I use a whitespace of 2 spaces and when not? I think I dont really get it


#4

In Python indentation has nothing to do with readability. It is the interpreter’s way of knowing that a block of code is inside a function or control flow structure such as for, while, if. That will come up in time but for now do not use any indentation for inline code (such as above). Just use a new line for each statement with no indent.


#5

Oh, I see. I was doing html before and I understand (at least I think so) now when to do it. its when you have a block element and you want to put within some other functions, then you have to use whitespace?


#6

Whitespace is mostly intended for readability in HTML (which completely ignores it) to help with spotting errors. In Python we do not use it arbitrarily but as a requirement.

if x:
    return x
else:
    return False
while x:
    x -= 1
    print x
for x in y:
    print x
def foo(bar):
    return bar

Above, the indentation is not for looks, but for practical purposes… To tell the interpreter which code is part of the block.

Don’t give this too much thought, just now. Put aside whitespace (except for line breaks after statements) until the subject comes up in Control Flow and Conditionals, and the Functions units.


#7

Thank you very much :smiley:


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.