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

weimeng yeo
PLUS
weimeng yeo
Courses Plus Student 301 Points

I am getting syntax error on the challenge.

I keep getting a syntax error on my code. Can someone assist ? Tks !!!

time = 15

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

membership.py
time = 15

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

3 Answers

Hi there, here's the error message:

python3 membership.py                                                                                                                                          
  File "membership.py", line 5                                                                                                                                         
    if time in store_hours = 15:                                                                                                                                 
                           ^                                                                                                                                     
SyntaxError: invalid syntax

Here the error message tells us the line number (5) and the statement that's causing the problem, it's

if time in store_hours = 15: 

And we see it's just an accidental typo that caused the problem - the "= 15" part. Did you copy and paste the time variable from the first line of the file? it's an easy mistake - I think most of us have made similar ones, even apple did the same thing a few years ago and caused a huge vulnerability in Safari :)

What's the error message? Did you still include the "=15" part?

weimeng yeo
PLUS
weimeng yeo
Courses Plus Student 301 Points

Ah. Thanks again. Yeah, i was doing on a txt and pasting it on the website.

weimeng yeo
weimeng yeo
Courses Plus Student 301 Points

Hmm, i am still getting an error on the syntax. I have tried to type manually as opposed to pasting it and still have an issue.

weimeng yeo
PLUS
weimeng yeo
Courses Plus Student 301 Points

Yes, see below.

time = 15
store_open = None
store_hours = [9, 10, 11, 12, 13, 14, 15, 16, 17,18]
if time in store_hours =15:
File "<stdin>", line 1
if time in store_hours =15:

Ah okay, sorry my mistake - bit of a miscommunication!

It's the "=15" that's causing the problem. Short answer is just delete it. Longer, explaination follows:

if time in store_hours:

will work just fine because the time variable holds the value 15, so to python it will look like:

if 15 in [9, 10, 11, 12, 13, 14, 15, 16, 17,18]:

which is of course true.

However that "= 15" is trying to store a variable. "=" is called the assignment operator. It's job is to store whatever is on the right of it in a variable named whatever is on the left of it. what's on the left of it is "if time in store_hours", and that is not a valid variable name, so you get a syntax error.