Object-oriented Programming and Data Structures | CS 241

09 Prepare : Checkpoint B - More exceptions

After completing (or while completing) the preparation material for this week, complete the following exercise.

Overview

This checkpoint is intended to help you practice the syntax of exceptions.

Instructions

Write a program that computes the value of 1/n for different values of n. To accomplish this, adhere to the following guidelines:

Sample Output

The following is an example of output for this program:


Enter a number: 4
The result is: 0.25

Here is another example:


Enter a number: word
Error: The value must be a number

Here is another example:


Enter a number: 0
Error: Cannot divide by zero

Here is another example:


Enter a number: -10
Error: The value cannot be negative

Testbed

An auto-grading testbed script is provided for you to help evaluate your program. This same testbed script will be used to grade your program. It is pass/fail, so your program must pass the testbed completely for you to receive credit for this assignment. You may run the testbed as many times as you like.

You must use exceptions for this program in order to receive credit. Similarly, you must raise the errors in one function and catch them in another.

Helpful commands


testBed cs241/check09b check09b.py
submit check09b.py