python - My answers are 5, 4, 3, 2,but when I run the code ,the answers are 5, 4.Why? -
num = 5 if num > 2: print(num) num -= 1 print(num)
here thoughts:5>2,5,4; 4>2,4,3; 3>2,3,2; 2.so answers 5, 4, 3, 2 when run code,the answers 5 ,4. don't understand it.
use while
instead of if
.
>>> num = 5 >>> while num > 2: ... print(num) ... num -= 1 # 5 # 4 # 3 >>> print(num) # 2
Comments
Post a Comment