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

Filip Zwozdziak
Filip Zwozdziak
553 Points

Python Basics problem with IF CONDITIONS

The following is my code (first two lines were provided as part of the exercise):

store_open = None store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18] time = 8 if time not in store_hours: store_open = True elif time in store_hours: Store_open = False

The INSTRUCTIONS to the exercise:

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). I need you to make an if condition that sets store_open to True if time is in store_hours. 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
store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
time = 8
if time not in store_hours:
    store_open = True 
elif time in store_hours:
    Store_open = False 

3 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

You should set store_open to True when time is in store_hours and otherwise to False. Your code is doing the reverse. You've also capitalized store_open in the last line. Also, you shouldn't set the value of time in your code so remove the line:

time = 8
Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

You are making your true & false to the opposite of what they should be. If time not in store_hours, then the store is closed or store_open should be false.

The correct answer should look as follows:

store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
if time not in store_hours: #This will check if the number is in store_hours, if NOT, it should be False to indicate that the store is closed.
    store_open = False 
elif time in store_hours: #This will assume it did find the number in store_hours. This should be True to indicate that the store is open.
    store_open = True