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

nicholas Christie
nicholas Christie
433 Points

i swear this is it?

?

membership.py
time = 15

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

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Nicholas,

You're close and on the right track, but there are just a couple of things.

The major one is a syntax error. Your else statement should not be indented. It needs to be the same level as the if statement.
Second, the instructions do not ask you to print anything (And you can't print a Boolean). The instructions say to change the value of the variable based on the condition.
The store_open variable is declared and assigned an initial value outside of the if/else block, so it is available globally and just needs to changed inside the block. So, you'll need to reassign the value and not use print().

Give it another go with this in mind. I'm sure you can get it! :)

Keep Coding! :dizzy:

nicholas Christie
nicholas Christie
433 Points

changed values still not working

time = 15

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
Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

I had to add markdown to your comment so the code can be read. When posting code, you need to use Markdown, or the code snippet is not readable in the Community. There is a Markdown Cheatsheet above the "Post" button for your reference.

Now, your code. The assignments are correct, but now the indentation is backwards. The assignments need to be inside the if / else statements. You had the indentation correct in your original post, except for the else that should not have been indented.

time = 15

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
nicholas Christie
nicholas Christie
433 Points

it was indentation error on line 11 and only had 9 lines. I was kind of confused but starting to see why its important to pay attention to indentation thanks i got it.