DEV Community

Guna Ramesh
Guna Ramesh

Posted on

Python

1.Excepted output:
10 8 6 4 2
program:
a=10
while a>=1:
print(a,end=" ")
a=a-2
output:
10 8 6 4 2

What happens in this program?

Initially, the value of a is set to 10. The while loop checks whether a is greater than or equal to 1.

Since the condition is true, the loop starts executing. Inside the loop, the current value of a is printed, followed by a space.

After printing, the value of a is decreased by 2 (a = a - 2), and the updated value is stored back in the same variable.

This process continues:

First iteration → a = 10
Second iteration → a = 8
Third iteration → a = 6
Fourth iteration → a = 4
Fifth iteration → a = 2

When a becomes 0, the condition a >= 1 becomes false, and the loop stops.

Output:
10 8 6 4 2

This task for you
15 12 9 6 3

Top comments (0)