0
why is it whenever i use else: it always shows syntax error?
9 Antworten
+ 6
# The 'else' is a part of if-else sequence, therefore that should follow an 'if' with the same indentation
___________________
if 1:
print('give away')
else:
print('eat them yourself')
___________________
By the way, this just fixes the Syntax Error but not the Logical Error. If you encounter an error regarding this code coach, feel free to ask for help. Thanks.
+ 3
Garry Kasparov G.O.A.T
If you inspect Cyan original response, you will note he has placed the else statement in line with the if statement - same indentation.
This associates the else response to the if query
+ 3
Garry Kasparov G.O.A.T I think you are talking about the different indendation of two statement or body in my previous comment. I just noticed it.
It was my typo and my mistake, I've edited it. I apologise if that confused you.
+ 2
Cyan I think so there is also a problem in building the logic too
+ 2
Garry Kasparov G.O.A.T By logical errors, means that it may not pass all or some of the challenge's test cases or requirements or expected output from the code coach.
+ 1
Cyan its fine it worked thank you
+ 1
Rik Wittkopp but his statements after the conditions are not on the same indentation.
0
Atul the logic of what?
0
Cyan is the indentation of the else statement meant to be different to the statement of the if statement?