invalid syntax | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

invalid syntax

when i program in 3.5.2 if 1+1==2: if 2*2==8: print("if") else: print("else") this program shows invalid syntax please help?

14th Aug 2016, 6:18 AM
Rajiv Chatterjee
Rajiv Chatterjee - avatar
3 Answers
+ 3
1- Don't forget indentation. 2- you must add if statement then else.. But you added 2 if statements, you should have used (elif) .. 3- here is an example that works for your idea : if ((1+1==2) and (2*2==8)) : print ("if") else: print ("else")
14th Aug 2016, 9:44 AM
Abdulrahman Alshab
Abdulrahman Alshab - avatar
+ 1
I tried the code then after running into the syntax problem a couple hundred times I found out that after pressing enter for print("if") we tend to directly put else: we press enter and that's the problem. Doing this you directly correlate else with print this is wrong. Too overcome this press backspace behind else: then press enter.
22nd Aug 2016, 1:34 PM
Vishal Gali
Vishal Gali - avatar
Vishal Gali you are genius! it works! thank you
24th Aug 2016, 1:05 PM
Raptor “Pro” Games
Raptor “Pro” Games - avatar