0
I am getting invalid syntax while using else statement. If anyone can heLP me please help? It's a python code.
X=2 if x>1: print("yes") else: Syntaxerror:Invalid syntax (after pressing enter)
9 ответов
+ 1
Else expects an non empty code block.
+ 1
x = 2
if x > 1:
print("yes")
else:
print("no")
If you don't want anything to happen if x is not over 1, then don't write an else statement :)
+ 1
Why you left else empty
Line 5
else:
print("no")
Try this it will help
0
Hi.
The code somehow appears to be python?
Well in this case the reason lies in the empty else block. There is nothing to be done and therefore an error is thrown. Put in a "pass" that does exactly nothing but makes the code valid. Be aware of case sensitivities.
x = 2
if x > 1:
print("yes")
else:
pass
Cheers.
0
Where I have to put a "pass"? Please tell me.
0
Can you give a example with a code?
0
You declered variable 'X' but used in if statement
0
Variable X and x are different so there is error in program