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

am I doing this if in statement right?

I am having problems with this code challenge I don't know if this is a issue with the code challenge or my self but it says that that the false store_open isn't false and if I change the time to a false int it says that the True open_store isn't true...

I don't understand how it needs to be both true or false!

membership.py
time= 13
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

4 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing great and your logic is spot on. The problem is that you're defining the time. This time is set by Treehouse and not yourself, so you're overwriting what Treehouse is testing. Simply remove this line:

time= 13

This is the line that's defining the time. But that time is being set elsewhere by Treehouse (and we don't know what it is). Hope this helps! :sparkles:

edited for additional note

This is mentioned in the instructions:

I'm going to create a variable named time. It'll be an integer for the current hour (well, what I want the current hour to be).

Thank you!

Jacob Herrington
Jacob Herrington
15,835 Points

This code is passing:

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

At a high level, you can understand this as, "If the value in time is in the array store hours, do the following, otherwise do something else".

Sun Min
Sun Min
2,941 Points

Jacob, i have a question. how it works without variable?

We have not defined the variable time? So how does Python consider what time is?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Bilal Ron! It's sort of hinted at in the instructions of the challenge..

It'll be an integer for the current hour (well, what I want the current hour to be).

What they mean here is that outside of your code Treehouse is going to set the value for time. Possibly multiple values to make sure that your code passes in every case. This means that you do not get to define the value of time. Treehouse is going to do that. Keep in mind that challenges are testing for very specific things and that the way you do it in a challenge may only partially represent the bigger picture.

edited for additional note

This is the same thing I tried to express in my original answer. Treehouse is setting the time. If you set it yourself, it overwrites what they're setting. Which, very likely, will make the results not match. Unless, of course, you happen to guess what they've sent.

Thanks, that was a good explanation, made the logic clear!