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 144,810 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 144,810 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.