In [2]:
# this generates a run-time error when you enter a non-number
# for example enter "heavy" and you get a ValueError
weight = float(input("Enter product weight in Kg: "))
In [3]:
# This example uses try..except to catch the ValueError
try:
weight = float(input("Enter product weight in Kg: "))
print ("Weight is:", weight)
except ValueError:
print("You did not enter a number! ")
In [ ]: