+ 1

If statement problem

nun=7 if num <7, print (“3”) if num <5, print (“5”) if num ==7, print (“7”) why the answer is 3? Does it not 5?

8th Apr 2020, 7:44 AM
Arvonce
5 ответов
+ 5
Arvonce In response to your second question: num = 7 if num >3: #true print('3') # 3 is printed elif ..... etc # progam is not looking at these lines of code because it has already returned a true statement. Remember: if returns a result if true elif means that if the IF statement is not true, then is this statement true. else returns a result if no true options exist, or if false.
8th Apr 2020, 8:32 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 7
num = 7 if num < 7: print("3") elif num < 5: print("5") elif num == 7: print("7") please do revise the if else concepts and your question is not clear enough.
8th Apr 2020, 7:49 AM
RKK
RKK - avatar
+ 3
👋😁👍 Sweet
8th Apr 2020, 8:35 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thanks Rik, I got it now
8th Apr 2020, 8:34 AM
Arvonce
0
num = 7 if num > 3: print("3") elif num < 5: print("5") elif num == 7: print("7") what is the output? I did the tutour if statement, the practice question, which gave a answer 3 I cant understand, why is 3
8th Apr 2020, 7:54 AM
Arvonce