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

How I solve this problem? =c

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.

store_open = None store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18] time = 18 if time in store_hours: print("We are open") else: store_open = 1

membership.py
store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
time = 18
if time in store_hours:
    print("We are open")
else:
    store_open = 1

2 Answers

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

Hi there, Alex Galhardo!

In the first line of the challenge instructions it says that they'll create the time variable for you. Here you're overwriting what Treehouse is sending with time = 18. They're going to decide what the time is and test it... not you :smiley:

Secondly, your else statement should set store_open equal to False if the time is not found in the open hours. Take a look:

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

Thanksss :D

Idan Melamed
Idan Melamed
16,285 Points

Hi again Alex,

  1. You don't need to assign the variable time. Assume it will be provided by Kenneth.
  2. If your statement is true, you should set store_open to True, if it is false you should set store_open to False.

You can check my solution here: https://trinket.io/python/9038bcbe7e