0

I have a problem with indentation. I keep getting indentation error trying the if-sratements.

31st Dec 2018, 10:22 AM
Elvis Stephen
Elvis Stephen - avatar
4 Antworten
+ 2
Can you post a code sample that gives you an IndentationError? That would make it much easier to help you. In general, if/else statements should look like this: if condition: ****do_something() else: ****do_something_else() * denotes whitespace. Typically, four blanks are used. Missing or inconsistent use of whitespace will lead to an Indentation Error: if condition: do_something() # error: missing indentation if condition: ****do_something() else: **do_something_else() # error: inconsistent use of whitespace
31st Dec 2018, 10:29 AM
Anna
Anna - avatar
+ 1
Can you share your code?
31st Dec 2018, 10:26 AM
Juho Pesonen
Juho Pesonen - avatar
0
Scripts of same block needs have same spacing at front of line
31st Dec 2018, 10:29 AM
Gordon
Gordon - avatar
0
Another way to put it: Not indenting your code in for example C will be okay for the compiler, but people having to read your code (including you) will be mad, so very likely you are going to indent anyway. Consequently, not having to write all these brackets and semicolons any longer becomes a net plus for Python. ;-)
31st Dec 2018, 1:41 PM
HonFu
HonFu - avatar