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

Tariq Kfaery
Tariq Kfaery
956 Points

i get syntax error in line 15 but i have no line 15 in my code

if gives me syntax error invalid syntax (<str> line 15) but i dnt have a line 15 in my code i have only 9 lines

membership.py
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

2 Answers

Sorry, I haven't done the python track so I don't know the specific question, but I'll try and help based on what I see

Just quickly, your indentation is incorrect in your if/else- the else should line up vertically with the if. Remember that python uses the amount of invisible space to group things together. So just a heads up, once you resolve the str error, you'll get an indentation error.

EDIT: That's it, that's the fault. I juist tried your code in the question and the code parser is calling it a <str> error instead of an indentation error. I guess the line number is wrong because of whatever code wraps your work before it is checked by the site.

One other quick tip: Whilst this code has the desired effect, it can be risky to initiate a variable to a type of none when we definitely know what type it will have later. For example, Here we know that store_open will be a bool. If something goes wrong, and it skips getting assigned for some reason, later on your code might throw a "none-type" error because you expected it to already have a true or false value by the time the interpreter got that far. So I see that the question starts off with a type of none, but it's probably good practice to replace that lol.

You could try initiating the value to be false by default, and only changing it if the answer were true for example, or you could just do something like this:

store_open = time in store_hours

The "else:" should be aligned with the "if"