Write a Python program to accept two positive integers x and y from the user and then find and print all the prime numbers between x and y. 

Answer:

Answer by student

x = int(input( "Enter the lower limit: " ))

y = int(input( "Enter the upper limit: " ))

 

print( "The prime numbers between" , x, "and" , y, "are:" )

 

for num in range(x, y + 1 ):

  if num > 1 :

    is_prime = True

    for i in range( 2 , num):

      if num % i == 0 :

        is_prime = False

        break

    if is_prime:

      print(num)

Detailed answer by teachoo

The rest of the post is locked. Join Teachoo Black to see the full post.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo