06.0 Python‎ > ‎Python Projects‎ > ‎Dice Project‎ > ‎

Dice v5-Errors

Objectives

Add error checking to the user's input
If the user enters the correct data your program will functions as expected. However, if the user accidentally enters incorrect data, your program could have unexpected results.

Learn to catch user input errors by using new Python keywords:
  • try:
  • except:
One way to increase the robustness of a program is to add logic to a program to prevent the program crashing unexpectedly. For example, to catch a user input error, when a user enters a word instead of an integer. This strToInt() function will replace Python's int() function

Program Description

The following is a function. Add it to your Dice program to catch input errors caused by the user entering a non-integer value. This function will be called from the setNumberOfRolls() and setNumberOfSides() functions.

Once this function is added and called from the setNumberOfRolls() and setNumberOfSides() functions add code to the two setter functions that will ensure the values are positive. Similar to the following code.




Comments