Python program to print all Prime numbers in an Interval
In this article, you will learn to print all the prime numbers between a given interval.
What is a Prime number?
Step to create these programs:
- First, we take the first number as 1
- Then we take the second number from the user
- Then we iterate the for loop from first to last+1
- Then we check the number is greater than 1
- Then we iterate again for the second loop from 2 to num
- Then we check the num, divide the num from the for loop and the check is equal to zero
- Otherwise, print num
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Python program to display all the prime numbers within an interval # prime number in python # take input of lower and upper limit from the user first= 1 #Take the input from the user: last= int(input("Enter the number: ")) for num in range(first,last+ 1): if num > 1: for i in range(2,num): if (num % i) == 0: break else: print(num) # prime number in python - docodehere.com