about last quiz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

about last quiz

why the answer is 3, the (num) also equal 7 ,i expected that logical the answer is 7,i can't get it

27th Aug 2017, 8:32 PM
maxfreeman
maxfreeman - avatar
1 Answer
+ 8
please for mext time make an effort to wrote the code in here it wasn't so easy to find num = 7 if num > 3: ( I ) print("3") if num < 5: ( II ) print("5") if num == 7: ( III ) print("7") what's going on in here is like so: you actually have a nested structure ( I ) is the first condition and it is True since 7 is bigger than 3 right after printing "3" another condition ( II ) is checked and evaluated as False since 7 is not smaller than 5 the last condition ( III ) is actually nested inside ( II ) and since it was evaluated as False and did not entered the block, the last condition is never evaluated and the code finished after the ( II ) condition is evaluated as False
27th Aug 2017, 8:46 PM
Burey
Burey - avatar