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

Why do i get an indentation error i am using print() after an if statement

Why am i getting an identation error in workspaces

if today in days_open: print ("Come on in") ...but i get an indentation error

Steven Parker
Steven Parker
243,656 Points

For your indentation to display properly, edit your question and use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

I can't be sure what your specific problem is, but from my experience, it's most likely due to you mixing spaces with tabs. I've definitely done this before (on multiple occasions, haha), and I don't remember Kenneth talking too much about it, but basically, you can either hit tab or hit the space bar 4 times to indent your code, but you can only pick one of those methods. Either will work, but once you pick one you have to stick with it throughout that entire chunk of code. Troubleshoot this by deleting the indented space on every line and then re-inserting it with the correct number of tabs (or sequences of four spaces. Just not both of them on the same line.) Hopefully this helps!

1 Answer

After the if statement press <ENTER> on the second line press <TAB BUTTON> to make an indent of 2 or 4 spaces depending in the code editor you are using lastly avoid using <SPACE BUTTON> in your code or code environment that's the key of avoiding indentation error. format you code to look like mine below.

if today in days_open: 
    print ("Come on in")

hope it works...