Python Program To Print All The Prime Numbers Between An Interval.

In this tutorial, we will learn how to write a program to print prime numbers using Python 3 programming language.


Python Program To Print All The Prime Numbers Between An Interval


You just need to take two number as input from stdin and you need to find prime numbers between those two numbers and print them.


Input Format

You will be taking two numbers as an input from stdin one on each line respectively.


Constraints

1 <= N <= 10000


Output Format

You need to print the prime numbers one on each line to the stdout.


Sample TestCase 1


Input


900

1000


Output


907

911

919

929

937

941

947

953

967

971

977

983

991

997


Allowed Languages:

C, C++, C++11, C++14, C#, Python, Python 3, Java, Java 8, PHP, Perl, Ruby, NodeJS, Scala, Swift, Go, Bash, Smslltalk, R, etc.


ETS2 | Manchester To Birmingham


In this tutorial, we will use Python 3 programming language to solve the problem given above. If you also know any programming language out of the programming languages ​​given in the problem, then you can also solve this problem by using that programming language.





So let's... solve this problem using Python 3 programming language...

Program 1: Simple Python Program

# Date: Sunday, 29-11-2020
# @author: Ankur Saxena
# Platform: Linux Ubuntu 18.04 Lts/x64/Python 3.8/Visual Studio Code

# Program Start

num1 = 900
num2 = 1000

for num in range(num1, num2 + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)

# Program End
# Save this file as "FindPrimeNo.py"
# Execute: $ python3 FindPrimeNo.py [press the Enter key]






Program 2: Python Program To Print All The Prime Numbers

# Date: Sunday, 29-11-2020
# @author: Ankur Saxena
# Platform: Linux Ubuntu 18.04 Lts/x64/Python 3.8/Visual Studio Code

# Program Start

# take the input from the user

num1 = int (input("Please enter first number : "))
num2 = int (input("Please enter second number : "))

print("Prime numbers between", num1, "and", num2, "are:")

for num in range(num1, num2 + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)

# Program End
# Save this file as "FindPrimeNo1.py"
# Execute: $ python3 FindPrimeNo1.py [press the Enter key]

So friends! In today's tutorial, that's all... see you soon with a new tutorial/article. Till then stay safe, stay healthy, be happy and keep studying...