0
When ever i use else: and then i hit enter then syntax errors pops ip
If else
20 odpowiedzi
0
Your code should fail in line 2 already, because you haven't defined a variable x, only X.
It would be best if you upload your code in 'Code Playground' and link it here.
+ 4
In the code you posted here, there is syntax errors when you write the start of a line with capitals, but I suppose your smartphone does that 'for' you.
Taking that away, you shouldn't get an error.
If in front of your 'if' there is no whitespace, then in front of your 'else' there also must not be whitespace.
The statements that belong to the blocks need to be indented though.
+ 1
Please show us your code, then we can tell you what exactly is wrong.
+ 1
Are you using indentation in front of that else? (You shouldn't.)
+ 1
So you made an empty line?
Okay, you must not do that. Python doesn't know then, that the else belongs to the if.
Immediately after the if block ends, there needs to be the else block.
(Some things in interactive mode are different: You 'finalize' a block by hitting enter twice.)
+ 1
Thank you sooooo much
+ 1
Finally, :) sorry I killed your so much time
0
X=5
If x == 4:
Print ("hello")
else: (now when I hit enter to write next line it says Syntax error)
0
Check this please.
num = 7
If num == 5:
print("hello")
else: (now when I hit enter I got SyntaxError: invalid Syntax)
0
Are you trying this in interactive mode in IDLE on your computer?
0
Yes
0
It's showing error both ways
0
But when I wrote the same code on cellphone it works fine.
0
Yeah first letter was capitalised by smartphone.
Yeah I haven't used any whitespaces as you said.
Can you please write a code with else so that I can post in my pc to check if I'm missing something .
0
Did you manually write your code there or did you copypaste it from somewhere?
0
if 1:
1
else:
2
0
No I did manually
0
By writing your code I too get error message after else
0
One thing I forgot to mention I typed enter twice before writing else
0
Hehe, good that we found it!