0
a = 6 while a >=2: print(a) a -= 1 b = 6 while True: print(b) b -=1 if b <=2: break
When first code ends at 2 , why second at 3 ?
2 ответов
+ 2
a>=2 and b<=2 has a difference for the first condition 6,5,4,3,2>=2 will evaluate to true,at 1>=2 it will fail...here if condition true is printing the values.
But for b<=2....6,5,4,3<=2 will evaluate to false! But ,At 2<=2 it will be true so it breaks...here if condition true is breaking the loop.
+ 1
When b counts down to 3, and the print() statement shows 3, the next line decrements b to 2. Now the 'if' statement says to break the loop because b = 2 matches the condition.