0

Else Statement

This is what I entered when I started trying myself, chain = 20 if chain == 10: print ("Equals 10") else: if chain ==10*2: print ("Equals 10*2") else: if chain == 4*5: print ("Equals 4*5") The output for this was "Equals 10*2) even though 4*5 is also = 20. Can someone explain why I can't seem to have two different outputs.

21st Nov 2019, 2:48 AM
Leticia
Leticia - avatar
2 Réponses
+ 5
Leticia In conditional statement if one condition is come as true other condition is not even checked and execute so result halts when it faces first truth condition so the output is "Equals 10*2"
21st Nov 2019, 3:09 AM
GAWEN STEASY
GAWEN STEASY - avatar
0
if the if condition turns true, then the else if and else condition is ignored. here is an example x = 5 if x == 5: print("if statement") else if x == 5: print("else if statement") >>> if statement you can do this instead if you want to print both x = 20 if x == 10*2: print("equals 10*2") if x == 4*5: print("equals 4*5") >>> equals 10*2 equals 4*5
21st Nov 2019, 9:43 AM
Shen Bapiro
Shen Bapiro - avatar