##### ► Python program to subtract two numbers with input validation check

Steps followed:
1. take input from user and store in num1 and num2 variables
2. validate user input by converting to float
3. print result

Program
``````#python program to subtract two numbers with input validation check

#getting input from user and storing in num1 and num2 variables
num1=input("enter value for first number: ")
num2=input("enter value for second number: ")

#validating user input
try:
num1=float(num1)
num2=float(num2)
print("you have entered valid numbers")

#subtracting num2 from num1 and storing value in "sub" variable
sub = num1-num2

#printing result
print("%0.2f - %0.2f = %0.2f"%(num1,num2,sub))

except:
print("you have entered invalid numbers")
``````

Output
``````enter value for first number: 396
enter value for second number: 254
you have entered valid numbers
396.00 - 254.00 = 142.00

enter value for first number: py
enter value for second number: 27
you have entered invalid numbers``````