When Python hits an error it stops and shows a traceback. try and except let your code handle an error you expect instead:
try:
hours = float(text)
except ValueError:
hours = None
Python runs the try block. If a ValueError happens there, it jumps to the except block and carries on; if not, it skips the except block. Name the error you expect, such as ValueError, KeyError or ZeroDivisionError. A bare except: catches everything, including typos in your own code, and hides real bugs.
Read the last line of a traceback first. It names the error type, which is what goes after except.
Your own functions can raise errors too. raise ValueError("hours must be between 0 and 24") stops bad input early, with a message that says what's wrong.