##### ► Python program to print all prime numbers below a given number

Steps followed:
1. take input from user and store in num variable
2. validate user input by converting to integer
3. check if number is 0,1 or 2, if yes print there is no prime below these numbers. Else check all numbers between range 2(inclusive) and num(exclusive) for prime.
4. print the number if its prime else check for next number

Program
``````#python program to print all prime numbers below a given number

#getting input from user and storing in num variables
num=input("enter a number below which you want to print all prime numbers: ")

#validating user input
try:
num=int(num)
print("you have entered valid number")

#2 is smallest prime number, hence there is no prime number below 2
if num in (0,1,2):
print("there is no prime number below %d"%(num))
else:
print("all prime numbers below %d are:"%(num))
for j in range(2,num):
count=0
i=2
while i<j:
if j % i == 0:
count += 1
i += 1
else:
i += 1
#prime numbers are only divisble by 1 and the number itself
if count == 0:
print(j)
else:
continue

except:
print("you have entered an invalid number")
``````

Output
``````enter a number below which you want to print all prime numbers: 10
you have entered valid number
all prime numbers below 10 are:
2
3
5
7

enter a number below which you want to print all prime numbers: 2
you have entered valid number
there is no prime number below 2

enter a number below which you want to print all prime numbers: prime
you have entered an invalid number``````