0
Does >/< actually mean >=/<= in a while loop?
Python while loop problem i = 0 x = 0 While i < 4: x+ = i i+ = 1 print(x) Steps taken 1. x = 0 i = 1 2. x = 1 i = 2 3. x = 3 i = 3 4. x = 6 i = 4 The correct answer was 6 So my question is does this < actually mean <= since it stops on the loop when i = 4? Or do you stop halfway through the loop when x = 6 but before you solve i+ to produce a 4?
1 Respuesta
+ 1
It stops at i = 4 because the condition is "while i is less than 4"
Instead, i <= 4 means "while i is less than OR EQUAL to 4", so it will be executed one more time and "i" will end up being 5