Page 1 of 1

Python: try, except, and else

Posted: Tue Apr 07, 2026 6:04 pm
by Jason
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}.")