Problems on Loops
1. Print Numbers from 1 to 10
Problem: Print numbers from 1 to 10.
Example Output:
1 2 3 4 5 6 7 8 9 10
2. Sum of First N Natural Numbers
Problem: Calculate the sum of numbers from 1 to N.
Example Input: N = 5
Output: 15
3. Print Each Character in a String
Problem: Print each character of a string.
Input: "Python"
Output:
P y t h o n
4. Print Even Numbers from 1 to 20
Problem: Print only even numbers between 1 and 20.
Output:
2 4 6 8 10 12 14 16 18 20
5. Print List Elements Using Loop
Problem: Display all elements from a list using a loop.
Input: ["apple", "banana", "cherry"]
Output:
apple
banana
cherry
6. Reverse Counting from 10 to 1
Problem: Print numbers from 10 down to 1.
Output:
10 9 8 7 6 5 4 3 2 1
7. Print Multiplication Table of a Number
Problem: Take a number and print its multiplication table up to 10.
Input: 3
Output:
3 x 1 = 3
3 x 2 = 6
...
3 x 10 = 30
8. Find the Factorial of a Number
Problem: Find the factorial of a given number.
Input: 5
Output: 120
9. Print Digits of a Number (Using while loop)
Problem: Display each digit of a number separately.
Input: 1234
Output:
4
3
2
1
10. FizzBuzz
Problem: Print numbers 1–20 but:
- Print “Fizz” if divisible by 3
- Print “Buzz” if divisible by 5
- Print “FizzBuzz” if divisible by both
Output Example:
1
2
Fizz
4
Buzz
...
FizzBuzz
11. Sum of Even Numbers in a List
Problem: Calculate the sum of all even numbers in a list.
Input: [1, 4, 7, 10, 12]
Output: 26
12. Count Vowels in a String
Problem: Count the number of vowels in a given string.
Input: "Python is fun"
Output: 4
13. Print Numbers Divisible by 4 and 6
Problem: Print numbers from 1 to 50 divisible by both 4 and 6.
Output:
12 24 36 48
14. Cumulative Sum of List
Problem: Print cumulative sum at each step from a list.
Input: [2, 5, 3, 7]
Output:
2 7 10 17
15. Print Multiples of 3 and 5
Problem: Print numbers between 1–50 divisible by 3 or 5.
Output Example:
3 5 6 9 10 12 ... 45 48 50
16. Reverse a String
Problem: Print a string in reverse.
Input: "Python"
Output: nohtyP
17. Find Numbers with Even Digits
Problem: Print numbers from 1–100 that have an even number of digits.
Output Example:
10 11 12 ... 99
18. Find the Maximum Number in a List
Problem: Find the largest number in a list.
Input: [5, 12, 3, 21, 7]
Output: 21
19. Count Digits and Letters in a String
Problem: Count letters and digits separately in a string.
Input: "Python3.8"
Output:
Letters: 6
Digits: 2
20. Fibonacci Numbers Less Than N
Problem: Print all Fibonacci numbers less than a given number N.
Input: N = 20
Output:
0 1 1 2 3 5 8 13
21. Print Odd Numbers in a List
Problem: Print all odd numbers from a given list.
Input: [2, 7, 4, 9, 12, 15]
Output: 7 9 15
22. Count Uppercase and Lowercase Letters
Problem: Count the number of uppercase and lowercase letters in a string.
Input: "Python Is Fun"
Output:
Uppercase: 3
Lowercase: 8
23. Print Squares of Numbers
Problem: Print squares of numbers from 1 to N.
Input: N = 5
Output:
1 4 9 16 25
24. Print Cubes of Numbers in a List
Problem: Print cubes of numbers from a given list.
Input: [1, 2, 3, 4]
Output:
1 8 27 64
25. Print Numbers Divisible by 7 but Not by 5
Problem: Print numbers from 1–100 divisible by 7 but not by 5.
Output Example:
7 14 21 28 ... 91 98
26. Print Factorials of Numbers in a List
Problem: Print factorial of each number in a list.
Input: [3, 4, 5]
Output:
6 24 120
27. Count Words in a Sentence
Problem: Count the number of words in a given sentence.
Input: "Python is fun to learn"
Output: 5
28. Print Prime Numbers from 1 to N
Problem: Print all prime numbers from 1 to N.
Input: N = 20
Output:
2 3 5 7 11 13 17 19
29. Sum of Digits of Numbers in a List
Problem: Print sum of digits for each number in a list.
Input: [12, 34, 56]
Output: 3 7 11
30. Check Palindrome Numbers in a List
Problem: Print all numbers from a list that are palindromes.
Input: [121, 123, 454, 567, 787]
Output: 121 454 787