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
deelan pather
299 Pointspython 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
1 Answer
Steven Parker
243,657 Points
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
Jeff Morrison
5,917 PointsJeff Morrison
5,917 PointsWhat 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:
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: