Programming Examples

Python program to print all the prime numbers in the given range


Write a Python program to print all the prime numbers in the given range. an Interval. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. 

Solution

start=int(input("Enter the Start value"))
end=int(input("Enter the End value"))
print("Prime numbers between ",start," and ",end)
for a in range(start,end+1):
    n=a
    flag=True
    for b in range(2,(n//2)+1):
        if n%b==0:
            flag=False
    if flag==True and n>1:
        print(n,end=',')
Output

Enter the Start value11

Enter the End value50

Prime numbers between  11  and  50

11,13,17,19,23,29,31,37,41,43,47

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad