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
6 Réponses
+ 3
You forgot to type ':'.
if (condition):
# some statements
elif (condition 2):
# other statements
else:
# other statements
+ 1
Change the else to elif.
It means else if.
+ 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
- 1
Can you try now?They make other error ;-;
- 1
Ok.
- 1
Thanks, so else is used before elif?