- 2
Doesn't the number satisfy both condition 1 and 3 (num > 3, Num ==7) then how does it only display 3?
3 Respostas
+ 1
This is a nested IF condition. The 1st IF condition is True, thus it prints "3", but the 2nd IF condition returns False, thus it does not print anything AND does not test for the 3rd IF condition (since 2nd IF condition is False). Thus only "3" is printed, and not "37".
0
what? pls explain you question
0
Hello! here is my explanation:
num = 7 <---This is the given value
*if num > 3: <----This is the 1st condition, if it´s not satisfied then the program goes to condition #2
print("3")
*if num < 5: <---- This is the second condition,if not satisfied goes to condition #3
print("5")
*if num ==7: <----This is the third and final condition.
print("7")
As we can note, the number given is 7 and 7==7 right? Mathematically it is true, but the "If" condition in the program evaluates the input in a logical way as I explained above: Value given, if condition #1 is true the program ends, if not then evaluates condition #2, and so on. Because the first condition is TRUE (7 is greater than 3) then the program ends and the result is 3 because that is the instruction( print("3")).
*P.D. In fact we will never get to the final condition (7==7) because the program would end immediately in the first condition.
*P.D. Sorry if I do not explain myself clearly.