0

If and Else

Ok guys, here I go again. My code return a error and an can't identified the error.I just check the operators, variables and number and result in nothing. I will try to put the code in the comment. https://code.sololearn.com/cDNQ4avicjVg/?ref=app

5th Nov 2017, 12:01 AM
TheEditor
TheEditor - avatar
6 Answers
+ 3
You forgot to type ':'. if (condition): # some statements elif (condition 2): # other statements else: # other statements
5th Nov 2017, 12:04 AM
Boris Batinkov
Boris Batinkov - avatar
+ 1
Change the else to elif. It means else if.
5th Nov 2017, 12:07 AM
Boris Batinkov
Boris Batinkov - avatar
+ 1
No, else is the last and it is optional. If first condition is False, then it checks the second, if it's False and there is no other elif conditions, it execute the code in the else block. Here, if there is no else, you'll not know whether a = b. a = 20 b = 20 if (a > b): print("%d > %d" % (a, b)) elif (a < b) print("%d < %d" % (a, b)) else: print("%d = %d" % (a, b)) # Output: 20 = 20
5th Nov 2017, 12:10 AM
Boris Batinkov
Boris Batinkov - avatar
- 1
Can you try now?They make other error ;-;
5th Nov 2017, 12:06 AM
TheEditor
TheEditor - avatar
- 1
Ok.
5th Nov 2017, 12:08 AM
TheEditor
TheEditor - avatar
- 1
Thanks, so else is used before elif?
5th Nov 2017, 12:09 AM
TheEditor
TheEditor - avatar