0
nested if statements (python)
What is the output of this code? num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") why is the answer 3 and not 37?
3 odpowiedzi
+ 3
num = 7
if num > 3: #True
print("3") #prints 3
if num < 5: #False
print("5") #skip
if num ==7: #skip
print("7") #skip
The third if condition will only evaluate if it's parent (second if ) is true
+ 2
"If num ==7: print(" 7") " isn't executed because "if num < 5" is false. Reduce the indent of your last if-statement and the 7 will be printed.