Confused 🤔 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Confused 🤔

Num=7 If num>3: Print(“3”) If num <5: Print(“5”) If num ==7: Print(“7”) 3

17th Mar 2018, 12:36 PM
Abayo
Abayo - avatar
2 Answers
+ 2
Those are nested if statements. Since the first if statement already returns true (7 > 3 returns true), it stops checking for the rest of the conditions and executes the instructions assigned to that if statement. If you wanted it to really return 7, then "if num == 7:" must be the first check to be done.
17th Mar 2018, 12:49 PM
apex137
apex137 - avatar
+ 2
Hello Abayo! The problem is that the condition num < 5... The program checks num < 5 and since this is not true it stops there. It never gets to the line if num == 7. Check out this code. Instead of num < 5, I did num > 5. Run it. :) https://code.sololearn.com/cM2o374cSTic/?ref=app
17th Mar 2018, 1:01 PM
cyk
cyk - avatar