Python Program to Print all Prime Numbers in an Interval

Python Program to Print all Prime Numbers in an Interval

 # Python program to display all the prime numbers within an interval

# change the values of lower and upper for a different result
lower = 800
upper = 1000

# uncomment the following lines to take input from the user
#lower = int(input("Enter lower range: "))
#upper = int(input("Enter upper range: "))

print("Prime numbers between",lower,"and",upper,"are:")

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


output:
Prime numbers between 800 and 1000 are:
809
811
821
823
827
829
839
853
857
859
863
877
881
883
887
907
911
919
929
937
941
947
953
967
971
977
983
991
997

In [1]:

Comments

Popular posts from this blog

C Program to Display the ATM Transaction

Java programming language