Python While Loop Practice Questions
1. Counting Numbers
Write a program that uses a while loop to print numbers from 1 to 10.
Expected Output:
1
2
3
...
10
2. Sum Until Zero
Ask the user to enter numbers repeatedly. Keep a running total. Stop when the user enters
0, then print the total sum.
Example Interaction:
Enter a number: 5
Enter a number: 3
Enter a number: 0
Total sum: 8
3. Guess the Number
Write a guessing game where the program randomly selects a number between 1 and 20,
and the user keeps guessing until they get it right.
Hint: Use import random and [Link](1, 20)
4. Multiplication Table Generator
Ask the user for a number, and use a while loop to print its multiplication table up to 12.
Example Output (user enters 5):
5x1=5
5 x 2 = 10
...
5 x 12 = 60
5. Countdown Timer
Ask the user to enter a number, then use a while loop to count down from that number to 1.
Example Output (user enters 5):
5
4
3
2
1
Done!