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=',')
▶ RUN

Output/ Explanation:

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

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad