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

Josh Tucker
Josh Tucker
1,171 Points

Conditional Value and Membership challenges in python

I'm confused by the question. Kenneth says he's going to make a variable in both of these. Does that mean my code will work without the variable. I think I have to use this variable in the if statement so shouldn't I have to define it? Also, the question says to make a statement that says if the condition is true then make another variable true. We only printed strings in the video if a condition is true. Not really sure how to do this.

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

2 Answers

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

He does mean that he's going to make a time variable and pass info to you. You'll have no idea of knowing what this time is. It could be 6 ... 8...9... There's no way to know, so your code has to work for any time he picks. You will not be printing anything in this challenge. All you'll do is set store_open to true or false depending on if the time he sends happens to be in the store_hours. Take a look at my code.

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
Josh Tucker
Josh Tucker
1,171 Points

Thanks! At first it didn't work then I went back and capitalized the first letter of True and False and that did the trick. Is it always necessary to capitalize true and false in python?

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

Yes, you must capitalize them :) I just used the lower case in my text to mean generically true or false... not how it looks in code. Sorry for any confusion.