+ 2

Getting a syntaxError when doing this:

So I'm trying to run the following code: userInput = input() if userInput = "yellow": (the error happens here) print("invalid color") Else: print("finished") So i put yellow when it asks for input but get a syntaxError. Any help?

7th Nov 2016, 1:12 PM
wafflez
wafflez - avatar
2 Antworten
+ 7
You are using the assignment operator (=) in the if statement instead of the equal to operator (==). It should be like this: if userInput == "yellow": By the way, the else stament has to be in lowercases (else instead of Else) or you will get another error. Hope it helps
7th Nov 2016, 1:41 PM
Nelson Urbina
Nelson Urbina - avatar
+ 1
Python doesn't test if assignment (=) works. Use equivalence (==) instead. 'else' should be all lowercase.
7th Nov 2016, 1:40 PM
Kirk Schafer
Kirk Schafer - avatar