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 https://teamtreehouse.com/library/python-basics/logic-in-python/membership

hi i am confused when they ask to return a condition as true or as false

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

What do you mean "when they ask to return a condition as true of false"? In thise case, store_open is a variable that tells you whether or not the store is open. True: you can go shopping. False: Store closed, come back later. So in the code, he will give you an hour. If the hour is in the allowed store hours, then the store should be open. If not, then the store is closed.

The beauty of Python is that the way it's described in English is pretty much how it's written in code:

if time in store_hours:  ## if the time he gives you is in the list of hours that the store is open
    store_open = True ## then make sure you tell people the store is open
else:  #if the hour is not in the list of store hours...
    store_open = False #then it's not open.

Setting store_open to True or False doesn't mean much here, but if you're writing a program then you'll need it later on. For example if you're writing code to manage your lighting system:

if store_open:
    lights_on()
else:
    lights_off()

1 Answer

Steven Parker
Steven Parker
243,657 Points

:point_right: You can do this even more efficiently:

Since you're performing a true/false test to check if the time is in the store hours, you can just assign that value directly to store_open:

    store_open = time in store_hours