- 3

Else statement

if 1 + 1 == 2: if 2 * 2 == 8: print("if") else: print("else") I did not get why is the output "else". I thought there is no output here.

12th Sep 2020, 5:45 AM
Lilit Ghazaryan
Lilit Ghazaryan - avatar
1 Answer
+ 1
first condition(1+1==2) of if is true, so the interpreter checks the condition of next if, which is false(2*2==8); so it goes to the next statement else where you are printing else. if the above condition is true. if you dont want any out just change the indentation of else. if 1+1==2: if 2*2==8: print("if") else: print("else")
12th Sep 2020, 6:31 AM
Nandini Rajput
Nandini Rajput - avatar