Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Class07 Python Homework

The document discusses adding functions to geometry.py and geometry_main.py to calculate areas and volumes of geometric shapes like triangles, circles, spheres, cuboids, cones using given formulas. It provides examples of calculating areas and volumes of these shapes and calling the functions from geometry_main.py.

Uploaded by

alexzhang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Class07 Python Homework

The document discusses adding functions to geometry.py and geometry_main.py to calculate areas and volumes of geometric shapes like triangles, circles, spheres, cuboids, cones using given formulas. It provides examples of calculating areas and volumes of these shapes and calling the functions from geometry_main.py.

Uploaded by

alexzhang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Procedural Programming – Homework

The area of a rectangle is given by the following formula:

Area = Width x Length

The following module geometry.py defines a function calculate_rectangle_area that


implements the formula.

The function is called from geometry_main.py, which prints the result rounded to two decimal
places:

Perform a web search or consult your geometry textbook for the required mathematical
formulae:

1. Add a new function named calculate_triangle_area that will return the area of a
triangle.

Call the function from geometry_main.py with height parameter set to 6.2, the base
parameter set to 3.5, and print the result.

2. Add a new function named calculate_circle_area that will return the area of a circle.

(π is defined by math.pi)

Call the function from geometry_main.py with radius parameter set to 4.8, and print the
result.

3. Add a new function named calculate_sphere_area that will return the surface area of a
sphere.

Call the function from geometry_main.py with the radius parameter set to 3.3, and print
the result

4. Add a new function named calculate_cuboid_volume that will return the volume of a
cuboid (also known as rectangular prism).

Call the function from geometry_main.py with length parameter set to 1.7, width
parameter set to 2.9, height parameter set to 4.3, and print the result.

1
5. Add a new function named calculate_sphere_volume that will return the volume of a
sphere.

Call the function from geometry_main.py with radius parameter set to 3.2, and print the
result.

6. Add a new function named calculate_cone_area that will return the surface area of a
cone.

Call the function from geometry_main.py with height parameter set to 5.3, the radius
parameter set to 2.5, and print the result

7. Add a new function named calculate_cone_volume that will return the volume of a
cone.

Call the function from geometry_main.py with height parameter set to 5.7, the radius
parameter set to 2.3, and print the result.

You might also like