May-22-2019, 02:11 PM
You are converting to float on lines 8 and 10, but you aren't trying to catch errors until lines 12-20. If you want to catch the errors being raised, you need to either move your try blocks back to where the float(input(...)) calls are, or you need to wait to convert to float until the try block.
You are going to have problems later on, though. You are just printing a warning if an error is raised, you are not actually dealing with the problem. In your example, you may print a warning that the second number is invalid, but then your program is still going to subtract Hi from 54. You probably want to put everything into a while loop:
You are going to have problems later on, though. You are just printing a warning if an error is raised, you are not actually dealing with the problem. In your example, you may print a warning that the second number is invalid, but then your program is still going to subtract Hi from 54. You probably want to put everything into a while loop:
while True: try: num1 = float(input('Enter second number: ')) break except ValueError: print('Please enter a valid number.')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures