Explanation:
-
Initialization:
n = 9 -
Loop condition:
The while loop runs as long as n > 1. -
Inside the loop:
print(n, end=" ") → prints the current value of n on the same line with a space.
n //= 2 → integer division by 2 (floor division). Equivalent to n = n // 2.
Iteration breakdown:
-
First run: n = 9 → prints 9, then n = 9 // 2 = 4
-
Second run: n = 4 → prints 4, then n = 4 // 2 = 2
-
Third run: n = 2 → prints 2, then n = 2 // 2 = 1
-
Now n = 1 → condition n > 1 is False, loop ends.
Final Output
9 4 2✅ So the loop keeps dividing n by 2 (integer division) until it becomes ≤ 1.


0 Comments:
Post a Comment