Skip to content

Update area.py #2524

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 4 commits into from
Oct 4, 2020
Merged
Changes from 3 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
25 changes: 25 additions & 0 deletions maths/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,30 @@ def area_circle(radius: float) -> float:
return pi * radius ** 2


def area_rhombhus(base: float, height: float) -> float:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def area_rhombhus(base: float, height: float) -> float:
def area_rhombus(base: float, height: float) -> float:

"""
Calculate the area of a rhombhus

>>> area_rhombhus(10, 20)
100.0
>>> area_rhombhus(-1, -2)
Traceback (most recent call last):
...
ValueError: area_rhombhus() only accepts non-negative values
>>> area_rhombhus(1, -2)
Traceback (most recent call last):
...
ValueError: area_rhombhus() only accepts non-negative values
>>> area_rhombhus(-1, 2)
Traceback (most recent call last):
...
ValueError: area_rhombhus() only accepts non-negative values
"""
if base < 0 or height < 0:
raise ValueError("area_rhombhus() only accepts non-negative values")
return 1 / 2 * base * height
Copy link
Member

Choose a reason for hiding this comment

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

Probably make it take two diagonals as parameters.



def main():
print("Areas of various geometric shapes: \n")
print(f"Rectangle: {area_rectangle(10, 20)}")
Expand All @@ -197,6 +221,7 @@ def main():
print("\nSurface Areas of various geometric shapes: \n")
print(f"Cube: {surface_area_cube(20)}")
print(f"Sphere: {surface_area_sphere(20)}")
print(f"Rhombhus: {area_rhombhus(10, 20)}")


if __name__ == "__main__":
Expand Down