30 Python Programming Questions on using While Loops
Q 1. Print numbers from 1 to 5.
Expected Output:
1
2
3
4
5
Q 2. Calculate the sum of numbers from 1 to 10.
Expected Output
55
Q 3. Print all even numbers from 1 to 20.
Expected Output:
2
4
6
8
10
12
14
16
18
20
Q 4. Print the multiplication table of 5.
Expected Output:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Q 5. Print numbers from 10 to 1 in descending order.
Expected Output:
10
9
8
7
6
5
4
3
2
1
Q 6. Print the first 5 natural numbers using a while loop.
Expected Output:
1
2
3
4
5
Q 7. Find the factorial of a number (e.g., 4).
Input: num = 4
Expected Output:
24
Q 8. Print the squares of numbers from 1 to 5.
Expected Output:
1
4
9
16
25
Q 9. Print the sum of the first 5 positive integers.
Expected Output:
15
Q 10. Check if a number is prime.
Input: num = 7
Expected Output:
Prime
Q 11. Print the Fibonacci sequence up to 10 numbers.
Expected Output:
0
1
1
2
3
5
8
13
21
34
Q 12. Count the number of digits in a number.
Input: num = 12345
Expected Output:
5
Q 13. Print the multiplication table of a given number.
Input: num = 3
Expected Output:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
Q 14. Find the sum of even numbers from 1 to 10.
Expected Output:
30
Q 15. Print a string multiple times (e.g., "Hello" 5 times).
Expected Output:
Hello
Hello
Hello
Hello
Hello
Q 16. Print a triangle pattern of stars.
Q 17. Print the first 5 numbers of the series 2, 4, 6, 8, 10.
Q 18. Print the sum of the squares of numbers from 1 to 5.
Expected Output:
55
Q 19. Print numbers from 1 to 10 with a message for multiples of 3.
Expected Output:
3 is a multiple of 3
6 is a multiple of 3
9 is a multiple of 3
Q 20. Print the sum of odd numbers from 1 to 10.
Expected Output:
25
Q 21. Print the factorial of numbers from 1 to 5.
Expected Output:
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 6
Factorial of 4 is 24
Factorial of 5 is 120
Q 22. Count the number of vowels in a string.
Input: string = "hello world"
Expected Output:
3
Q 23. Print all digits in a string.
Input: string = "abc123def456"
Expected Output:
1
2
3
4
5
6
Q 24. Generate the first 10 squares of numbers.
Expected Output:
1
4
9
16
25
36
49
64
81
100
Q 25. Print the sum of the first 10 positive integers.
Expected Output:
55
Q 26. Print all numbers from 1 to 20, but skip multiples of 4.
Expected Output:
1
2
3
5
6
7
9
10
11
13
14
15
17
18
19
Q 27. Print the cube of numbers from 1 to 5.
Expected Output:
1
8
27
64
125
Q 28. Print the reverse of a given string.
Input: string = "technovlogs"
Expected Output:
sgolvonhcet
Q 29. Print the first 10 numbers of the Fibonacci sequence.
Expected Output:
0
1
1
2
3
5
8
13
21
34
Q 30. Print numbers from 1 to 20, replacing multiples of 3 with "Fizz" and multiples of 5 with "Buzz".
Expected Output:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!