Your Turn: User-Friendly Hints

Now that you know what exception types to expect, you can modify your application to handle each one by responding with helpful user prompts. Your customers will thank you one day!

  • Change the except block from this:
    except Exception as e:
        print("Exception = ", e)
        et = type(e)
        print("Exception type = ", et)

...to this:

    except (TypeError, ValueError):                  
        print("Expected a number.")

    except ZeroDivisionError:
        print("Can't divide by zero.")
  • Test the responses to each exception you can create, including entering zero for the denominator, typing “Hello” instead of a number, and so on.

  • Now imagine you are using this app without knowing how to write code. Isn't this an improvement?