How to print all Prime numbers in an Interval with Python

Configurare noua (How To)

Situatie

Given two positive integers start and end. The task is to write a Python program to print all Prime numbers in an Interval.

Definition: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The first few prime numbers are {2, 3, 5, 7, 11, ….}.

Solutie

# Python program to print all
# prime number in an interval
# number should be greater than 1
start = 11
end = 25
for i in range(start, end+1):
    if i > 1:
        for j in range(2, i):
            if(i % j == 0):
                break
        else:
            print(i)
Output: 
11
13
17
19
23

Tip solutie

Permanent

Voteaza

(9 din 19 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?