Menu

Python IndentationError: expected an indented block after 'if', 'for' or a function definition
📰

Python IndentationError: expected an indented block after 'if', 'for' or a function definition

DEV Community: beginners·Craftstack Academy·about 12 hours ago
#T92BAHkX
#devtobeginners#devto#dev#line#print
Long article (1444 words) — no AI summary yet.
Reading 0:00
15s threshold

You write your first if : if the score is 50 or more, print "You passed". It looks right. You run it, and Python stops before it even starts:

File "main.py" , line 3 print ( "You passed" ) ^^^^^ IndentationError : expected an indented block after 'if' statement on line 2

Enter fullscreen mode

Exit fullscreen mode

Here is the program:

# main.py score = 75 if score >= 50 : print ( "You passed" )

Enter fullscreen mode

Exit fullscreen mode

Nothing is misspelled. The problem is two characters you can't see: the program is missing the spaces at the start of line 3.

What the error means

Read the last line first:

IndentationError : the problem is the indentation, the spaces at the start of a line.

expected an indented block : after a line that ends with a colon : , Python expects one or more lines that are pushed in to the right. That pushed-in group is called a block.

after 'if' statement on line 2 : the line that opened the block is the if on line 2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.