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 (2015) Logic in Python Membership

Luuk de Reus
Luuk de Reus
1,936 Points

I don't understand the IF and ELSE code format

I tried but failed. I don't know what I did wrong!

Thanks in advance Treehousers!

membership.py
time = 15

store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
if: time in store_hours
    store_open = True
    else:
        store_open = False

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

You are SO close! The else needs to be indented the same amount as the if

And the colon (:) goes at the end of the if statement.

The colon is used to signify a block of code follows this statement, the code block should be indent. The first line not indented as much as the code block marks the end of the code block.

In this case, the unindented else ends the code block from the if statement.

Post back if you need more help. Good luck!!!