update variable names for consistency using standard formula terms; (#2223)

* update variable names for consistency using standard formula terms;

fix flake8 syntax errors;

fix doctests;

* tweak to variable name
This commit is contained in:
lance-pyles 2020-07-22 15:49:34 -07:00 committed by GitHub
parent 9ec71cbdda
commit b3950035a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,14 +31,14 @@ def surface_area_sphere(radius: float) -> float:
return 4 * pi * pow(radius, 2) return 4 * pi * pow(radius, 2)
def area_rectangle(base, height): def area_rectangle(length, width):
""" """
Calculate the area of a rectangle Calculate the area of a rectangle
>> area_rectangle(10,20) >>> area_rectangle(10,20)
200 200
""" """
return base * height return length * width
def area_square(side_length): def area_square(side_length):
@ -48,24 +48,24 @@ def area_square(side_length):
>>> area_square(10) >>> area_square(10)
100 100
""" """
return side_length * side_length return pow(side_length, 2)
def area_triangle(length, breadth): def area_triangle(base, height):
""" """
Calculate the area of a triangle Calculate the area of a triangle
>>> area_triangle(10,10) >>> area_triangle(10,10)
50.0 50.0
""" """
return 1 / 2 * length * breadth return (base * height) / 2
def area_parallelogram(base, height): def area_parallelogram(base, height):
""" """
Calculate the area of a parallelogram Calculate the area of a parallelogram
>> area_parallelogram(10,20) >>> area_parallelogram(10,20)
200 200
""" """
return base * height return base * height
@ -75,8 +75,8 @@ def area_trapezium(base1, base2, height):
""" """
Calculate the area of a trapezium Calculate the area of a trapezium
>> area_trapezium(10,20,30) >>> area_trapezium(10,20,30)
450 450.0
""" """
return 1 / 2 * (base1 + base2) * height return 1 / 2 * (base1 + base2) * height
@ -85,24 +85,29 @@ def area_circle(radius):
""" """
Calculate the area of a circle Calculate the area of a circle
>> area_circle(20) >>> area_circle(20)
1256.6370614359173 1256.6370614359173
""" """
return pi * radius * radius return pi * pow(radius, 2)
def main(): def main():
print("Areas of various geometric shapes: \n") print("Areas of various geometric shapes: \n")
print(f"Rectangle: {area_rectangle(10, 20)=}") print(f"Rectangle: {area_rectangle(10, 20)}")
print(f"Square: {area_square(10)=}") print(f"Square: {area_square(10)}")
print(f"Triangle: {area_triangle(10, 10)=}") print(f"Triangle: {area_triangle(10, 10)}")
print(f"Parallelogram: {area_parallelogram(10, 20)=}") print(f"Parallelogram: {area_parallelogram(10, 20)}")
print(f"Trapezium: {area_trapezium(10, 20, 30)=}") print(f"Trapezium: {area_trapezium(10, 20, 30)}")
print(f"Circle: {area_circle(20)=}") print(f"Circle: {area_circle(20)}")
print("Surface Areas of various geometric shapes: \n") print("\nSurface Areas of various geometric shapes: \n")
print(f"Cube: {surface_area_cube(20)=}") print(f"Cube: {surface_area_cube(20)}")
print(f"Sphere: {surface_area_sphere(20)=}") print(f"Sphere: {surface_area_sphere(20)}")
if __name__ == "__main__": if __name__ == "__main__":
import doctest
doctest.testmod(verbose=True) # verbose so we can see methods missing tests
main() main()