The while loop and its practice
Answers are for parents and teachers.
1
In this program, what is k at the end?
Python
1n = 20 2k = 0 3while n > 1: 4 n //= 2 5 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.