#another way is to check if the entered number isdigit() #that way you will ensure unhandled exception incase of erroneus data number= input("What is your weight:") if number.isdigit(): kilos=int(float(number)) print ("The weight of the person is:" + str(kilos)) else: print("Error - Please enter a proper weight")
Here is what the above code is Doing:
1. The user is asked to enter a weight.
2. The input is stored in the variable number.
3. The input is checked to see if it is a digit.
4. If it is a digit, the input is converted to an integer and stored in the variable kilos.
5. The weight is printed.
6. If the input is not a digit, an error message is printed.