Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (Retired) Ins & Outs String Concatenation

What is a indentationError: expected an indented block

IndentationError: expected an indented block is what the console returns when my code is exactly what Kenneth has on this video lesson

name = input("What's your name? ")

if name == "Kris":

print(name + " is a lumberjack and he is ok!")

else: print(name + " sleeps all night and " + name + "works all day!")

Hi Kristopher,

Can you post the code that you have?

https://teamtreehouse.com/forum/posting-code-to-the-forum

Hi Kristopher,

Take a look at the Markdown Cheatsheet to see how to format code in the forum. the ` symbol (above the tab key) three times will show a block of code in the forum as I have done. Another three of those will show the end of the block. You get the nice syntax highlighting and everything!

2 Answers

Hi Kristopher,

This error typically means there is an error in indentation.

Most likely, you have something like this:

if condition:
do this
else:
do this

The problem is that Python requires formatting of blocks like this with indentation. So to correct that error in the above code, I would simply do:

if condition:
    do this
else:
    do this

Python is very picky about white space and indentation, more so than many languages. The reason is, rather than using curly braces and semi colons (like javascript or php) python looks for a return character (press enter/return on your keyboard) instead of the semicolon, and a colon with a tab after it for a opening curly brace. When the next piece of code is unindented, it expects that this is the same as a closing curly brace in Javascript or PHP.

Let me know if you'd like me to elaborate more!