Ishaq - While Loop Worksheet
Ishaq - While Loop Worksheet
Worksheet
Computer Science
Instructor: Bhaswar Sir
Topic: Python Iterative Statements- While Loop
1. Write a Python program to print all the numbers from 1 to 100 using a
while loop.
2. Create a Python program that accepts a number from the user and prints
the sum of all numbers from 1 to that number using a while loop.
3. Write a Python program to find the factorial of a given number using a
while loop.
4. Develop a Python program that reverses the digits of a number using a
while loop. For example, if the input is 1234, the output should be 4321.
5. Write a Python program to print the multiplication table of a number en-
tered by the user using a while loop.
6. Create a Python program that checks if a given number is a palindrome
or not using a while loop. A number is a palindrome if it reads the same
backward as forward.
7. Write a Python program to count the number of digits in a given number
using a while loop.
8. Develop a Python program to repeatedly ask the user to enter a password
until the correct password (pass123) is entered.
9. Write a Python program to find the sum of all even numbers and the sum
of all odd numbers between 1 and 100 using a while loop.
10. Create a Python program that simulates a countdown timer. Accept the
starting number from the user and count down to zero, printing each num-
ber.
11. Write a Python program to calculate the greatest common divisor (GCD)
of two numbers using the Euclidean algorithm with a while loop.
12. Create a Python program to find all prime numbers between 1 and 50 using
a while loop.
13. Write a Python program that asks the user to input numbers continuously
and stops only when the user enters 0. Finally, it should display the sum
of all the numbers entered.
14. Develop a Python program to generate the Fibonacci sequence up to n
terms using a while loop.
15. Write a Python program that simulates a basic ATM machine where the
user can:
Check balance
Deposit money
Withdraw money
Use a while loop to keep the program running until the user selects the
”Exit” option.
Page 2