+ 1

REGARDING THE IF STATEMENT

In one of the questions, num = 7 If num > 3: print ("3") If num < 5: print ("5") if num == 7: print ("7") The output is 3 Now my question is that why was it 3 that was printed as the output and not 7 since they both meet the conditions. Is it because 3 is the first condition?

7th Nov 2021, 9:21 PM
Chibuike Omenukor
Chibuike Omenukor - avatar
6 Respostas
+ 1
You are using nested if conditions. Your if num==7 : never met because it's already confirms that num<5 then how num==7 comes true.. Check this code and you may need to learn about identation in python. num = 7 If num > 3: print ("3") If num < 5: print ("5") if num == 7: print ("7")
7th Nov 2021, 9:29 PM
Jayakrishna 🇮🇳
+ 2
Look at the indentation: The if-statements are neseted. It would only print 7 if num was smaller than 5 and equal to 7 which can never be true
7th Nov 2021, 9:29 PM
Lisa
Lisa - avatar
+ 1
Oh I think I get it better. Thank You very much Lisa and Jayakrishna🇮🇳 Urrm....please what do you mean by "Nested"?
7th Nov 2021, 9:38 PM
Chibuike Omenukor
Chibuike Omenukor - avatar
+ 1
By "nested if-statement" I mean "one if-statement inside another if-statement"
7th Nov 2021, 9:50 PM
Lisa
Lisa - avatar
0
Wow! thank You Very Much for the materials.
8th Nov 2021, 1:50 PM
Chibuike Omenukor
Chibuike Omenukor - avatar