+ 1
Nested If Statement
This was the question What is the output of this code? num = 7 if num > 3: print("3") if num < 5: print("5") if num ==7: print("7") but it only yielded one answer. (3) I assumed the answer would be 3 7 I am a python n00b. Learning and implementing Python is part of my Data Analyst Nanodegree with Udacity, and I am using supplemental resources to gain comprehensive understanding of Python.. Can someone explain why this answer was only 3 and not 3\n7?
3 Antworten
+ 1
see carefully...
first num is 7...nice
then it enters 1st if statement
....if num>3 ----print("3")
((as 7>3 it prints 3...perfect)
......nested if num<5-----print("5")
((as 7 is not less than 5...wont run anything in the nested if..))
****the third if statement is in the 2 nd if statement...and as 2nd if statement is False
nothing in it gets to run...
+ 1
Thank you sayan chandra and Ehsan Askari for taking the time to answer my question. I understand now :)