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 trialweimeng yeo
Courses Plus Student 301 PointsI 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
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
Jon Mirow
9,864 PointsHi 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 :)
weimeng yeo
Courses Plus Student 301 PointsAh. Thanks again. Yeah, i was doing on a txt and pasting it on the website.
weimeng yeo
Courses Plus Student 301 PointsHmm, 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
Courses Plus Student 301 PointsYes, 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:
Jon Mirow
9,864 PointsAh 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.
Jon Mirow
9,864 PointsJon Mirow
9,864 PointsWhat's the error message? Did you still include the "=15" part?