Part of the series

Several example codes

~2 min read • Updated Oct 7, 2025

Program Overview

This Python program reads two numbers from the user and displays all prime numbers between them.
A prime number is a number greater than 1 that is divisible only by 1 and itself.


Python Code:


def is_prime(n: int) -> bool:
    if n < 2:
        return False
    for i in range(2, int(n / 2) + 1):
        if n % i == 0:
            return False
    return True

# Read inputs
start = int(input("Enter the first number: "))
end = int(input("Enter the second number: "))

print(f"\nPrime numbers between {start} and {end}:")
for num in range(start, end + 1):
    if is_prime(num):
        print(num)

Sample Output:


Inputs:  
First number: 10  
Second number: 30  

Output:  
Prime numbers between 10 and 30:  
11  
13  
17  
19  
23  
29

Step-by-Step Explanation:

- The is_prime function checks whether a number is divisible only by 1 and itself
- The program loops through all numbers between the start and end values
- If a number is prime, it is printed


Written & researched by Dr. Shahin Siami