Python Loops Practice Questions with Solutions

Python Loops Practice Questions with Solutions allow you to execute a block of code multiple times without writing the same code repeatedly. In this practice set, you’ll learn how to use for loops, while loops, the range() function, and loop control statements through practical Python programs.


1. Python Program to Print Numbers from 1 to 10 Using a for Loop

Difficulty: Foundation

Problem Statement

Write a Python program to print numbers from 1 to 10 using a for loop.

Expected Output

1
2
3
4
5
6
7
8
9
10

Python Solution

for number in range(1, 11):
    print(number)

Explanation

The range(1, 11) function generates numbers from 1 to 10.

Concepts Covered

  • for loop
  • range()

2. Python Program to Print Even Numbers from 1 to 20

Difficulty: Foundation

Problem Statement

Write a Python program to print all even numbers from 1 to 20.

Expected Output

2
4
6
8
10
12
14
16
18
20

Python Solution

for number in range(2, 21, 2):
    print(number)

Explanation

The third argument of range() specifies the step value.

Concepts Covered

  • for loop
  • range(start, stop, step)

3. Python Program to Calculate the Sum of First 10 Natural Numbers

Difficulty: Foundation

Problem Statement

Write a Python program to calculate the sum of numbers from 1 to 10.

Expected Output

Sum: 55

Python Solution

total = 0

for number in range(1, 11):
    total += number

print("Sum:", total)

Explanation

The variable total stores the running sum of all numbers.

Concepts Covered

  • for loop
  • Accumulator pattern

4. Python Program to Print the Multiplication Table of a Number

Difficulty: Foundation

Problem Statement

Write a Python program to print the multiplication table of a given number.

Python Solution

number = int(input("Enter a number: "))

for i in range(1, 11):
    print(f"{number} x {i} = {number * i}")

Sample Output

Enter a number: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50

Explanation

The loop repeats 10 times to generate the multiplication table.

Concepts Covered

  • for loop
  • range()
  • Formatted output

5. Python Program to Count the Digits in a Number

Difficulty: Practice

Problem Statement

Write a Python program to count the total number of digits in a given number.

Python Solution

number = int(input("Enter a number: "))
count = 0

while number != 0:
    number //= 10
    count += 1

print("Total Digits:", count)

Sample Output

Enter a number: 54892
Total Digits: 5

Explanation

Each iteration removes the last digit until the number becomes zero.

Concepts Covered

  • while loop
  • Integer division

6. Python Program to Reverse a Number

Difficulty: Practice

Problem Statement

Write a Python program to reverse a given number.

Python Solution

number = int(input("Enter a number: "))
reverse = 0

while number > 0:
    digit = number % 10
    reverse = reverse * 10 + digit
    number //= 10

print("Reversed Number:", reverse)

Sample Output

Enter a number: 12345
Reversed Number: 54321

Explanation

The last digit is extracted and added to the reversed number in each iteration.

Concepts Covered

  • while loop
  • Modulus operator

7. Python Program to Check Whether a Number is Prime

Difficulty: Practice

Problem Statement

Write a Python program to check whether a given number is prime.

Python Solution

number = int(input("Enter a number: "))

if number <= 1:
    print("Not a Prime Number")
else:
    is_prime = True

    for i in range(2, number):
        if number % i == 0:
            is_prime = False
            break

    if is_prime:
        print("Prime Number")
    else:
        print("Not a Prime Number")

Sample Output

Enter a number: 13
Prime Number

Explanation

A prime number has exactly two factors: 1 and itself.

Concepts Covered

  • for loop
  • break
  • Prime number logic

8. Python Program to Print a Right Triangle Star Pattern

Difficulty: Challenge

Problem Statement

Write a Python program to print the following star pattern.

Expected Output

*
**
***
****
*****

Python Solution

for row in range(1, 6):
    print("*" * row)

Explanation

The number of stars increases by one in each row.

Concepts Covered

  • Nested logic
  • Pattern printing

9. Python Program to Demonstrate break Statement

Difficulty: Challenge

Problem Statement

Write a Python program that prints numbers from 1 to 10 but stops when it reaches 6.

Python Solution

for number in range(1, 11):
    if number == 6:
        break

    print(number)

Expected Output

1
2
3
4
5

Explanation

The break statement immediately terminates the loop.

Concepts Covered

  • break
  • Loop control statements

10. Python Program to Demonstrate continue Statement

Difficulty: Challenge

Problem Statement

Write a Python program to print numbers from 1 to 10, but skip the number 5.

Python Solution

for number in range(1, 11):
    if number == 5:
        continue

    print(number)

Expected Output

1
2
3
4
6
7
8
9
10

Explanation

The continue statement skips the current iteration and moves to the next one.

Concepts Covered

  • continue
  • Loop control statements

Chapter Summary

After completing this chapter, you have learned:

  • for loop
  • while loop
  • range() function
  • Nested loops
  • break statement
  • continue statement
  • Prime number logic
  • Pattern printing
  • Counting and reversing numbers
  • Real-world loop-based programs

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top