+ 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?
6 Antworten
+ 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")
+ 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
+ 1
Oh I think I get it better. Thank You very much Lisa and Jayakrishna🇮🇳
Urrm....please what do you mean by "Nested"?
+ 1
By "nested if-statement" I mean "one if-statement inside another if-statement"
0
Identation information:
https://www.w3schools.in/JUMP_LINK__&&__python__&&__JUMP_LINK-tutorial/concept-of-indentation-in-python/
https://www.google.com/amp/s/www.freecodecamp.org/news/indentation-in-python/amp/
Nested if information:
https://kodify.net/python/if-else/nested-if/ https://www.programiz.com/python-programming/if-elif-else
Hope these helps..
You're welcome..
0
Wow! thank You Very Much for the materials.