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

Grayson Jones
Grayson Jones
550 Points

Syntax?

No idea

membership.py
time = 15

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

2 Answers

Richard Lambert
PLUS
Richard Lambert
Courses Plus Student 7,180 Points

Hello mate,

In Python, indentation is important as it is used to delineate code blocks. The Python Documentation shows the correct format for an if-else statement.

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

Hope this helps

Hi,

In my experience, when you use the if statement in that way, it works a bit different:

<return_value> if <condition> else <return_value_if_condition_is_not_met>

So if you want to use it for this challenge, you can do:

time = 15

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

I hope it helps.

Many thanks. Have a nice weekend,