why is it whenever i use else: it always shows syntax error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why is it whenever i use else: it always shows syntax error?

https://code.sololearn.com/c8noJ3XXz3BE/?ref=app

10th Feb 2021, 6:04 AM
Central Processing Unit
Central Processing Unit - avatar
9 Answers
+ 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.
10th Feb 2021, 6:07 AM
noteve
noteve - avatar
+ 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
10th Feb 2021, 7:05 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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.
10th Feb 2021, 7:11 AM
noteve
noteve - avatar
+ 2
Cyan I think so there is also a problem in building the logic too
10th Feb 2021, 6:11 AM
Atul [Inactive]
+ 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.
10th Feb 2021, 6:34 AM
noteve
noteve - avatar
+ 1
Cyan its fine it worked thank you
10th Feb 2021, 7:01 AM
Central Processing Unit
Central Processing Unit - avatar
+ 1
Rik Wittkopp but his statements after the conditions are not on the same indentation.
10th Feb 2021, 7:07 AM
Central Processing Unit
Central Processing Unit - avatar
0
Atul the logic of what?
10th Feb 2021, 6:13 AM
Central Processing Unit
Central Processing Unit - avatar
0
Cyan is the indentation of the else statement meant to be different to the statement of the if statement?
10th Feb 2021, 6:15 AM
Central Processing Unit
Central Processing Unit - avatar