-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Added some more comments to volume.py in maths folder #7080
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
Changes from 2 commits
2b8026a
722fb7d
0c718d2
4f0cc17
9f37864
ef25838
3971eeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,11 +2,14 @@ | |||||||||||||||||
Find Volumes of Various Shapes. | ||||||||||||||||||
Uncyclopedia reference: https://en.wikipedia.org/wiki/Volume | ||||||||||||||||||
""" | ||||||||||||||||||
|
||||||||||||||||||
# Imports | ||||||||||||||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
from __future__ import annotations | ||||||||||||||||||
|
||||||||||||||||||
from math import pi, pow | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
# Functions for calculating volumes of shapes | ||||||||||||||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
def vol_cube(side_length: int | float) -> float: | ||||||||||||||||||
""" | ||||||||||||||||||
Calculate the Volume of a Cube. | ||||||||||||||||||
|
@@ -30,8 +33,7 @@ def vol_cube(side_length: int | float) -> float: | |||||||||||||||||
|
||||||||||||||||||
def vol_spherical_cap(height: float, radius: float) -> float: | ||||||||||||||||||
""" | ||||||||||||||||||
Calculate the Volume of the spherical cap. | ||||||||||||||||||
:return 1/3 pi * height ^ 2 * (3 * radius - height) | ||||||||||||||||||
Calculate the Volume of the spherical cap | ||||||||||||||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
>>> vol_spherical_cap(1, 2) | ||||||||||||||||||
5.235987755982988 | ||||||||||||||||||
>>> vol_spherical_cap(1.6, 2.6) | ||||||||||||||||||
|
@@ -47,6 +49,7 @@ def vol_spherical_cap(height: float, radius: float) -> float: | |||||||||||||||||
... | ||||||||||||||||||
ValueError: vol_spherical_cap() only accepts non-negative values | ||||||||||||||||||
""" | ||||||||||||||||||
# Volume - 1/3 pi * height squared * (3 * radius - height) | ||||||||||||||||||
if height < 0 or radius < 0: | ||||||||||||||||||
raise ValueError("vol_spherical_cap() only accepts non-negative values") | ||||||||||||||||||
return 1 / 3 * pi * pow(height, 2) * (3 * radius - height) | ||||||||||||||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
@@ -261,6 +264,7 @@ def vol_sphere(radius: float) -> float: | |||||||||||||||||
... | ||||||||||||||||||
ValueError: vol_sphere() only accepts non-negative values | ||||||||||||||||||
""" | ||||||||||||||||||
# Volume - radius cubed * pi * 4/3 | ||||||||||||||||||
if radius < 0: | ||||||||||||||||||
raise ValueError("vol_sphere() only accepts non-negative values") | ||||||||||||||||||
return 4 / 3 * pi * pow(radius, 3) | ||||||||||||||||||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
@@ -284,6 +288,7 @@ def vol_hemisphere(radius: float) -> float: | |||||||||||||||||
... | ||||||||||||||||||
ValueError: vol_hemisphere() only accepts non-negative values | ||||||||||||||||||
""" | ||||||||||||||||||
# Volume - 4/3 * pi * radius cubed | ||||||||||||||||||
if radius < 0: | ||||||||||||||||||
raise ValueError("vol_hemisphere() only accepts non-negative values") | ||||||||||||||||||
return 2 / 3 * pi * pow(radius, 3) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
@@ -310,6 +315,7 @@ def vol_circular_cylinder(radius: float, height: float) -> float: | |||||||||||||||||
... | ||||||||||||||||||
ValueError: vol_circular_cylinder() only accepts non-negative values | ||||||||||||||||||
""" | ||||||||||||||||||
# Volume - radius squared * height * pi | ||||||||||||||||||
if height < 0 or radius < 0: | ||||||||||||||||||
raise ValueError("vol_circular_cylinder() only accepts non-negative values") | ||||||||||||||||||
return pi * pow(radius, 2) * height | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
@@ -344,6 +350,7 @@ def vol_hollow_circular_cylinder( | |||||||||||||||||
... | ||||||||||||||||||
ValueError: outer_radius must be greater than inner_radius | ||||||||||||||||||
""" | ||||||||||||||||||
# Volume - (outer_radius squared - inner_radius squared) * pi * height | ||||||||||||||||||
advik-student-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
if inner_radius < 0 or outer_radius < 0 or height < 0: | ||||||||||||||||||
raise ValueError( | ||||||||||||||||||
"vol_hollow_circular_cylinder() only accepts non-negative values" | ||||||||||||||||||
|
@@ -356,7 +363,7 @@ def vol_hollow_circular_cylinder( | |||||||||||||||||
def vol_conical_frustum(height: float, radius_1: float, radius_2: float) -> float: | ||||||||||||||||||
"""Calculate the Volume of a Conical Frustum. | ||||||||||||||||||
Uncyclopedia reference: https://en.wikipedia.org/wiki/Frustum | ||||||||||||||||||
:return 1/3 * pi * height * (radius_1^2 + radius_top^2 + radius_1 * radius_2) | ||||||||||||||||||
|
||||||||||||||||||
>>> vol_conical_frustum(45, 7, 28) | ||||||||||||||||||
48490.482608158454 | ||||||||||||||||||
>>> vol_conical_frustum(1, 1, 2) | ||||||||||||||||||
|
@@ -378,6 +385,7 @@ def vol_conical_frustum(height: float, radius_1: float, radius_2: float) -> floa | |||||||||||||||||
... | ||||||||||||||||||
ValueError: vol_conical_frustum() only accepts non-negative values | ||||||||||||||||||
""" | ||||||||||||||||||
# Volume - 1/3 * pi * height * (radius_1 squared + radius_2 squared + radius_1 * radius_2) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests are failing on:
Also, please move this line down to be just above the calculation. Make sure that the order of the values in the comment and in the calculation are the same. |
||||||||||||||||||
if radius_1 < 0 or radius_2 < 0 or height < 0: | ||||||||||||||||||
raise ValueError("vol_conical_frustum() only accepts non-negative values") | ||||||||||||||||||
return ( | ||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.