The while loop and its practice
Answers are for parents and teachers.
1
In this program, what is k at the end? n = 20 ⏎ k = 0 ⏎ while n > 1: ⏎ n //= 2 ⏎ k += 1
4
2
Write a program that prints the odd numbers from 1 to 9 with while.
i = 1 ⏎ while i <= 9: ⏎ print(i, end=" ") ⏎ i += 2
3
Find the product of the digits of a typed number (24 for 234).
x = int(input()) ⏎ p = 1 ⏎ while x > 0: ⏎ p *= x % 10 ⏎ x //= 10 ⏎ print(p)
4
Why is the starting value of p 1 in the product of digits program?
1 does not affect multiplication; with 0 the answer would always be 0.