Demonstrates handling exceptions when converting string to float : float « Data Type « Python Tutorial






try:
    num = float(raw_input("Enter a number: "))
except:
    print "Something went wrong!"

try:
    num = float(raw_input("\nEnter a number: "))
except(ValueError):
    print "That was not a number!"

try:
    num = float(raw_input("\nEnter a number: "))
except(ValueError):
    print "That was not a number!"
else:
    print "You entered the number", num








2.6.float
2.6.1.Real numbers are called floats or floating-point numbers
2.6.2.Demonstrates handling exceptions when converting string to float