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

Dina Climatiano
Dina Climatiano
10,862 Points

If statement using "in" in one of the exercises

I've checked this in the PERL in one of the workspaces and it works fine. However, in the challenge I get an error message telling me that 'store_open' is not True. What am I doing wrong?

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

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

2 Answers

Lukas Hölzer
Lukas Hölzer
37,349 Points

"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)." The variable is already created in the test. So just write your code without it and it will work.

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
Dina Climatiano
Dina Climatiano
10,862 Points

Thanks, it was driving me nuts for like 40 minutes. They should really phrase the challenges better, I thought I was supposed to create a variable called "time" and assign it a value.

Stephen Gheysens
Stephen Gheysens
11,935 Points

Hi Dina,

You've got the correct logic in the conditional (if) statement, but in this case, you're not supposed to assign time. Due to the instructions that say "I'm going to create a variable named time", you're only expected to use the variable, not assign it a value of 14 (so you can just remove your line 3).

Kenneth Love , I've seen multiple questions in the Community forums regarding this code challenge, and I think it would be helpful to include the assignment of time in the pre-rendered code - could this be updated? I agree that it's confusing to use a variable without seeing it previously assigned, especially for beginners.

Thanks,

Stephen

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Yeah, I could show the time variable, but then it leaves the challenge open to more hardcoded solutions, instead of thinking of it as a programming challenge. I'll see what I can do to make it a bit more lax, though.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Alright, after a bit of a revisit, I've updated the challenge. It now shows a time variable but, well, that variable doesn't matter :) Should be the same for any that students add.