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

Zachary Wheeler
Zachary Wheeler
1,157 Points

Conditional using In

I'm trying to input in within my if else statement. I think i'm mixing something up. Can you help me?

membership.py
store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
if store_open:
    store_hours = True
    if time in store_hours:
else:
    store_open = False

1 Answer

Hey Zachary, Your question is a little confusing? Did you mean you are trying to add an input into the script? I've provided a breakdown on how to pass this challenge only, please let me know if you are seeking help in a different way.

Here's the task:

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.

Let's Break it down.

So Kenneth has set a variable called time ( which we cannot see) which is an integer ( number), this integer/number could be anything from 1 - 24 ( for every hour of the day).

If the Time variable that Kenneth has set is in the store_hours list, we need to reassign the store_open to True. Otherwise, reassign store_open to False because the time is not in the store_hours list.

Here's the solution to the Challenge.

# lets assume Kenneth has set the time variable to 10. 
# so time = 10
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

#because the value of Time is set to 10, store_open will be set to True.
Zachary Wheeler
Zachary Wheeler
1,157 Points

No that's perfect, thanks. sorry for the confusion. I was just trying to figure out where the in should go within the if else statement. That makes sense though.