Skip to content
Sign upLog in
← Back to Community

It says invalid syntax but i dont know what is wrong.

Profile icon
astropi7

Repl.it - Giorgos - Google Chrome 15_11_2020 8_59_30 μμ (2)

Answered by realTronsi [earned 5 cycles]
View Answer
Voters
Profile icon
Emeka4
Profile icon
astropi7
Comments
hotnewtop
Profile icon
realTronsi

= is for assignment while == is for comparing

foo = 5

will set foo to 5

foo == 5

will compare foo with 5 to see if they are equal. In your case, change the = to == on the if statements

Profile icon
astropi7
Profile icon
RYANTADIPARTHI

wrong operator

You are using the wrong operator. You are using = instead of == the = is to assign values to a variable. == is to check.

Screenshot 2020-11-15 at 2.08.36 PM

As you see the red mark is below that =

Just use == and it should work

Profile icon
PattanAhmed

@astropi7
Hi,
Your program has some silly errors.

On line 5, you have:-

if age - 18 = 1

You have two erros as of now.
First one is of opperator, Second one is of Syntax of If statement

You will now need to change this: = to this: ==
and at the end of the Statement, you should add a colon : in order to get rid of that errors.

Your line 5 should like this:-

if age - 18 == 1:

This may clear out all the errors

That's it.
Thanks!

Hope this helps

Profile icon
Coder100

You forgot an =. To compare statements, you must use ==.

Fixed code:

print("hello") age = int(input("how old are you?")) if age > 17: if age - 18 == 1: print("you are an adult for 1 year") else: print("you are an adult for", 18-age, "years") else: if 18 - age == 1: print("you will be an adult in 1 year") else: print("you will be an adult in", 18 - age, "years")
Profile icon
DynamicSquid

Use == to compare things. = is only for assigning values to a variable.