I am new to python and trying to write a simple program in which i asked user to input a salary, what problem i am facing is i want user to only input integer or float data types when ever user input anything other than integer or float i will ask user to again input the salary, this can be done by using "try and except" method but i want to do this without using "try and except" method , my code by using "try and except" method is :
- Code: Select all
b = 0
while b == False:
a = float(raw_input("Give me a number"))
b = isinstance(a, float)
print "Could you at least give me an actual number?"
print "salary is: ", a
this is working fine as do what i exactly i want, but when i tried to do this with using "try and except" i got failed , need some help.
Thanking you in advance, Waiting for your reply