Python Python Basics (2015) Logic in Python Membership

Wilfried Allico
Wilfried Allico
2,310 Points

I 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.

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_opens = True
    else:
        store_opens = False

2 Answers

andren
andren
28,375 Points

Your code is quite close, but there are two issues:

  1. The name of the variable representing the store being open is named store_open not store_opens like you have written in your code.
  2. 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 the if 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.

Wilfried Allico
Wilfried Allico
2,310 Points

Thank you so much Andren. Your explanation of the code challenge really facilitate the solution of the problem.

Only 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.