Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions maths/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def surface_area_sphere(radius: float) -> float:
return 4 * pi * pow(radius, 2)


def area_rectangle(base, height):
def area_rectangle(length, width):
"""
Calculate the area of a rectangle

>> area_rectangle(10,20)
>>> area_rectangle(10,20)
200
"""
return base * height
return length * width


def area_square(side_length):
Expand All @@ -48,24 +48,24 @@ def area_square(side_length):
>>> area_square(10)
100
"""
return side_length * side_length
return pow(side_length, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds function call overhead but let's let it slide.



def area_triangle(length, breadth):
def area_triangle(base, height):
"""
Calculate the area of a triangle

>>> area_triangle(10,10)
50.0
"""
return 1 / 2 * length * breadth
return (base * height) / 2


def area_parallelogram(base, height):
"""
Calculate the area of a parallelogram

>> area_parallelogram(10,20)
>>> area_parallelogram(10,20)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

200
"""
return base * height
Expand All @@ -75,8 +75,8 @@ def area_trapezium(base1, base2, height):
"""
Calculate the area of a trapezium

>> area_trapezium(10,20,30)
450
>>> area_trapezium(10,20,30)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

450.0
"""
return 1 / 2 * (base1 + base2) * height

Expand All @@ -85,24 +85,29 @@ def area_circle(radius):
"""
Calculate the area of a circle

>> area_circle(20)
>>> area_circle(20)
1256.6370614359173
"""
return pi * radius * radius
return pi * pow(radius, 2)


def main():
print("Areas of various geometric shapes: \n")
print(f"Rectangle: {area_rectangle(10, 20)=}")
print(f"Square: {area_square(10)=}")
print(f"Triangle: {area_triangle(10, 10)=}")
print(f"Parallelogram: {area_parallelogram(10, 20)=}")
print(f"Trapezium: {area_trapezium(10, 20, 30)=}")
print(f"Circle: {area_circle(20)=}")
print("Surface Areas of various geometric shapes: \n")
print(f"Cube: {surface_area_cube(20)=}")
print(f"Sphere: {surface_area_sphere(20)=}")
print(f"Rectangle: {area_rectangle(10, 20)}")
print(f"Square: {area_square(10)}")
print(f"Triangle: {area_triangle(10, 10)}")
print(f"Parallelogram: {area_parallelogram(10, 20)}")
print(f"Trapezium: {area_trapezium(10, 20, 30)}")
print(f"Circle: {area_circle(20)}")
print("\nSurface Areas of various geometric shapes: \n")
print(f"Cube: {surface_area_cube(20)}")
print(f"Sphere: {surface_area_sphere(20)}")


if __name__ == "__main__":

import doctest

doctest.testmod(verbose=True) # verbose so we can see methods missing tests

main()