Self practiced Questions:
1) Five students enter the classroom one after another. The first student gets roll number 1, the second gets 2, and so on. Display the assigned roll numbers.
stud = 1
while stud <= 5:
print(stud, end = ' ')
stud = stud + 1
Output
1 2 3 4 5
2) A coach asks students to stand only at even-numbered positions in a queue. Display the first five positions.
coach = 2
while coach <= 10:
print(coach, end = ' ')
coach = coach + 2
Output
2 4 6 8 10
3) A newly constructed building has a special lift that does not stop on every floor. For safety reasons, it stops only at every third floor. A person enters the lift at the ground floor and presses the "Up" button. Display the first five floors where the lift will stop.
lift = 0
while lift <= 15:
print(lift, end = ' ')
lift = lift + 3
Output
0 3 6 9 12 15
4) A rocket launches with a countdown using only even numbers from 10. Display the countdown.
rocket = 10
while rocket >= 1:
print(rocket, end = ' ')
rocket = rocket - 2
Output
10 8 6 4 2
Top comments (0)