Python: try, except and else
Posted: Sun Jul 27, 2025 2:26 am
This tries a code to see if things are error-free. If not, the except stuff is returned. The except stuff has something following it, in this case, ValueError to indicate a wrong datatype.
Code: Select all
try:
float_number = float(input("Enter a float number":))
except ValueError:
return "Please pick a float datatype. That type is a number with a decimal point."
else:
print(f "Your chosen float number is { float_number}.")