COMP 141 Project 3: Geometry

You will write a program that allows the user to compute the areas of various geometric shapes, including circles, rectangles, squares, and triangles. This will be done using functions and if-else statements.

What you need to do

First, write four functions that compute the area of a circle, a rectangle, a square, and a triangle, respectively. All of these functions will return the areas of their shapes back to the place where they were called. None of the functions will directly print the areas; all of the printing will be handled by the main function.

Second, write your main() function so that the user is first asked what kind of shape they want to calculate the area of. The user will type in the name of the shape as a string (e.g., circle, rectangle, square, or triangle). Use if-elif-else statements to figure out what shape they wanted, then ask the user to type in the appropriate attributes of the shape (e.g., for circle you would ask for the area, for square you would ask for the length of side). Then display the area of the shape and end the program.

You may assume the user will type in the name of the shape either in all lowercase, or with a capital first letter (i.e., your program should work correctly for both "triangle" and "Triangle"). You do not have to handle any other type of capitalization. If the user types in an invalid shape name (like "TrIaNgLe" or "trapezoid"), your program should print an appropriate error message before ending.

You do not need to use any loops in this program.

Testing your program

You should test your program thoroughly to make sure all of your shape functions work. You may assume the user will never give "bad" input --- the user will always type in integers for the numbers, and never negative numbers or zero.

What to turn in

Through Moodle, turn in your code as a file called geometry_yourLastName_yourFirstName.py.

Challenge Problems

From time to time, I will offer "challenge problems" on assignments. These problems are designed to have little (but some) impact on your grade whether you do them or not. You should think of these problems as opportunities to work on something interesting and optional, rather than a way to raise your grade through "extra credit."

Policy on challenge problems:

Challenge problems for this assignment: