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 trialWilfried Allico
2,495 PointsI need help please
See that time variable? That's what time it currently is, at least for this test. But, when you submit your code, the time might change! I need you to make an if condition that sets store_open to True if time is in the store_hours list. Otherwise, if time isn't in store_hours, set store_open to False. You'll probably have to use if, else, and in to solve this one.
I cannot seem to figure this one out.
time = 15
store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
if time in store_hours:
store_opens = True
else:
store_opens = False
2 Answers
andren
28,558 PointsYour code is quite close, but there are two issues:
- The name of the variable representing the store being open is named store_open not store_opens like you have written in your code.
- The indentation (horizontal spacing) of your
else
statement and of the code inside it is wrong. In Python indentation is used to group code together and is therefore vital to get right.else
statements have to be indented to be at the same level as theif
statement they are attached to.
If you fix those two issues like this:
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
Then your code will pass.
Dimitri McDaniel
8,718 PointsOnly thing my untrained eye see's is that you added a plural to your store_open list take off the 's' and you should be a bit closer to your goal.
Wilfried Allico
2,495 PointsWilfried Allico
2,495 PointsThank you so much Andren. Your explanation of the code challenge really facilitate the solution of the problem.