CS 115 Lab 2, Part F: Computing the area of an equilateral triangle
[Back to Lab 2]
[Back to CS 115 schedule]
Background
In this part of the lab, we will extend our program from Part E
to compute the area of an equilateral triangle, given the length of a side.
Recall that the area of an equilateral triangle with side s is:
s2 * (square root of 3) / 4
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.159265359.
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.79020479.
The area of an equilateral triangle with side length 10.0 is 43.3012701892.
Instructions
- Continue working on lab02.py using PyCharm. Remember not to delete any of the existing code.
Also, do not prompt the user to enter another value.
- Just after the other calculations, add a line to the program to calculate the area of an
equilateral triangle whose side length is length. Store the result of this calculation
in a new variable with an appropriate name. Hint: math.sqrt(x) will compute
the square root of the number x.
- Add a line to the program to print the area of the equilateral triangle.
Be sure the wording matches the sample output exactly.
- Run your program. Make sure it matches the example (with the exception that the floating point accuracy or the number of digits could be different because that may depend on the specific machine you are using):
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.159265359.
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.79020479.
The area of an equilateral triangle with side length 10.0 is 43.3012701892.
- Run your program. Record the areas of the triangles in Question 11 of your writeup.
- Update your docstring to reflect what your program is doing now.
- Call an instructor or lab assistant over to demo your program.
- Continue to Part G.