Challenges

When you’ve finished writing the basic version of the program, try tackling some additional challenges:

  • Ensure that the user can enter only numbers for the bill amount and the tip rate. If the user enters non-numeric values, display an appropriate message and exit the program. Here’s a test plan as an example:

     
    Input:
     
    bill amount: abcd
     
    tip rate: 15
     
    Expected result: Please enter a valid number for
     
    the bill amount.
  • Instead of displaying an error message and exiting the program, keep asking the user for correct input until it is provided.

  • Don’t allow the user to enter a negative number.

  • Break the program into functions that do the computations.

  • Implement this program as a GUI program that automatically updates the values when any ...

Get Exercises for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.