i just started coding so thats why i dont know why this error is appearing
I’d be happy to help but this doesn’t look like Python. An IF statement ends with a colon and the following statement is indented like this:
print("I sense your energy.")
mood = input ("Type a number from 1-3") # Put the user input into a variable called "mood".
if mood == 1:
print("Mood is 1")
Indentation is critical for Python to work.
Also, do not provide screenshots of your code, just copy and paste your code into a code fence. Like my code above. This is so we can copy your code and fix it so you can learn from that.
Help us help you. Read this link first and learn how to format code so we can help you better. Do not use a screen shot of your code as some of us will copy and paste the code to get it to work for you, so you can learn from this. About the Python Help category You will get more help this way.
There are a number of free good tutorials on Python on Youtube. I like the ones by Indently. Have you done them yet? Search here: https://www.youtube.com/results?search_query=learn+python+tutorial+Indently Look for the tutorials that are more than 2 hours, those will have more info in them. Don’t skip parts, go through all parts.
=
and :=
are assignment operators. ==
is for checking equality, so it should actually be
if mood == 1:
print("Mood is 1")
in your example. However, this also does not work since input
returns a string, so it should actually be
if mood == "1":
print("Mood is 1")
Writing the if in one line is possible as well:
print("I sense your energy. Your true emotions are coming across my screen")
mood = input ("Type a number from 1-3 (DONT DO FOUR!!!)")
if mood == "1": print("Mood is 1")
if mood == "2": print("Mood is 2")
if mood == "3": print("Mood is 3")
Just remember, this is a string as written. Please append the int
to type cast it to an integer:
mood = int(input ("Type a number from 1-3")) # Put the user input into a variable
Update:
I do notice that you’re comparing to numerical strings below via double quotes. So disregard for this case. My apologies.
The detected SyntaxError is the ‘1’ followed by ‘print’, specifically, the ‘p’ of print, which is highlighted in red. Others have pointed out other problems. Note: if mood :=1:
is legal, but not what you want as it will always be True.