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

See that time variable?

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.

membership.py
time = 15

store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]

5 Answers

Patric Daniel Pförtner
Patric Daniel Pförtner
1,542 Points

Hi Nathaniel,

You are very close to the answer, here is how I did it:

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

Why are you learning Python? Maybe we have the same aims! I am learning it to bring my Start UP www.wolf-gate.com to the next level. Thank´s to Kenneth Love it´s easily possible :)

Patric Daniel Pförtner
Patric Daniel Pförtner
1,542 Points

If helpful then don´t forget to Upvote :)

Brian Galassini
Brian Galassini
3,521 Points

Just for FYI, while doing the work, it automatically indents "else" which renders an error message. Make sure you "un-indent" "else" so this doesn't happen. It took me a while to figure this one out.

Ferry J
Ferry J
941 Points

I get this error-message:

Bummer! invalid syntax (<string>, line 11)

But there's no line 11?

time = 15

store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]

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

Anyone here that is willing to point me in the right direction? :-)

Nevermind, I got it! Here's the right code:

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

Hi Nathaniel,

So you will first want to write the if statement that checks if (time in store_hours). Then if the time is in store_hours you will want (store_open to be = True.) If time is not in store_hours you will need the (Else:) statement which would be (store_open = False.)

Hope this helps.

For some reason i did it like this which is wrong

if time in store_hours: store_open = True else: store_open != False

the mistake was !=