CS 115 Lab 2, Part D: Compute the volume of a cube, the volume of a sphere, and the area of an equilateral triangle

[Back to lab instructions]


Background

In this part of the lab, you will extend your program from Part C to compute three more quantities:

Here is a sample of what your revised program will do. The user's input is italicized and underlined.

Enter a numeric value: 10
The area of a square with side length 10.0 is 100.0.
The area of a circle with radius length 10.0 is 314.159.
The volume of a cube with edge length 10.0 is 1000.0.
The volume of a sphere with radius length 10.0 is 4188.790.
The area of an equilateral triangle with side length 10.0 is 43.301.

To take the square root of a number in Python, you have two options:


Instructions

  1. Go back to lab02bcd.py. Remember not to delete any of the existing code. Also, do not prompt the user to enter another value. You should be using the same input value for all of the calculations.
  2. Just after the other calculations, add a line to the program to calculate the volume of a cube whose edge length is length. Store the result of this calculation in a new variable with an appropriate name.
  3. Add a line to the program to print the volume of the cube, rounded to 3 decimal places. Be sure the wording matches the sample output exactly.
  4. Run your program. Make sure it matches the example:
    Enter a numeric value: 10
    The area of a square with side length 10.0 is 100.0.
    The area of a circle with radius length 10.0 is 314.159.
    The volume of a cube with edge length 10.0 is 1000.0.
    
  5. Run your program. Record the volumes of the cubes in Question 8 of your writeup.
  6. Repeat this process for the sphere. Remember to round the result, and answer Question 9 in your writeup.
  7. Finally, repeat this process for the equilateral triangle. Remember to round the result, and answer Question 10 in your writeup. Make sure that your output looks identical to the sample output when the user inputs a value of 10. The user's input is italicized and underlined.
    Enter a numeric value: 10
    The area of a square with side length 10.0 is 100.0.
    The area of a circle with radius length 10.0 is 314.159.
    The volume of a cube with edge length 10.0 is 1000.0.
    The volume of a sphere with radius length 10.0 is 4188.790.
    The area of an equilateral triangle with side length 10.0 is 43.301.
    
  8. Update your docstring to reflect what your program is doing now. Be sure that it also includes your name.
  9. Call an instructor or lab assistant over to demo your program.
  10. Continue to Part E.