Demonstrates handling exceptions when converting string to float : Float : Data Type PYTHON TUTORIALS


PYTHON TUTORIALS » Data Type » Float »

 

Demonstrates handling exceptions when converting string to float


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



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Data Type
» Float