-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Dodecahedron surface area and volume #6606
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
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d2bd767
Hexagonal number sequence
shri30yans b40553d
Update hexagonalnumbers.py
shri30yans a9bbf96
Update hexagonalnumbers.py
shri30yans 8acb035
Update hexagonalnumbers.py
shri30yans 56c8f54
Update hexagonalnumbers.py
shri30yans c5c70b0
Update and rename hexagonalnumbers.py to hexagonal_numbers.py
cclauss 0212ecc
Length must be a positive integer
cclauss 3525aae
Merge branch 'TheAlgorithms:master' into master
shri30yans 6a39c10
Create dodecahedron.py
shri30yans bc9f6d9
Update dodecahedron.py
shri30yans ca2a742
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 24c835a
Update dodecahedron.py
shri30yans 8fe2b08
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5114808
Update dodecahedron.py
shri30yans adab173
Update dodecahedron.py
shri30yans 34ad557
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aaf9515
Update dodecahedron.py
shri30yans 8f1850f
Update dodecahedron.py
shri30yans b14eb4c
Apply suggestions from code review
shri30yans aaa6f99
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4e7f590
Apply suggestions from code review
cclauss ff4477f
Update dodecahedron.py
cclauss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# dodecahedron.py | ||
|
||
""" | ||
A regular dodecahedron is a three-dimensional figure made up of | ||
12 pentagon faces having the same equal size. | ||
""" | ||
|
||
|
||
def dodecahedron_surface_area(edge: float) -> float: | ||
""" | ||
Calculates the surface area of a regular dodecahedron | ||
a = 3 * ((25 + 10 * (5** (1 / 2))) ** (1 / 2 )) * (e**2) | ||
where: | ||
a --> is the area of the dodecahedron | ||
e --> is the length of the edge | ||
reference-->"Dodecahedron" Study.com | ||
<https://study.com/academy/lesson/dodecahedron-volume-surface-area-formulas.html> | ||
|
||
:param edge: length of the edge of the dodecahedron | ||
:type edge: float | ||
:return: the surface area of the dodecahedron as a float | ||
|
||
|
||
Tests: | ||
>>> dodecahedron_surface_area(5) | ||
516.1432201766901 | ||
>>> dodecahedron_surface_area(10) | ||
2064.5728807067603 | ||
>>> dodecahedron_surface_area(-1) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Length must be a positive. | ||
""" | ||
|
||
if edge <= 0 or not isinstance(edge, int): | ||
raise ValueError("Length must be a positive.") | ||
surface_area = 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2) | ||
return surface_area | ||
|
||
|
||
def dodecahedron_volume(edge: float) -> float: | ||
""" | ||
Calculates the volume of a regular dodecahedron | ||
v = ((15 + (7 * (5** (1 / 2)))) / 4) * (e**3) | ||
where: | ||
v --> is the volume of the dodecahedron | ||
e --> is the length of the edge | ||
reference-->"Dodecahedron" Study.com | ||
<https://study.com/academy/lesson/dodecahedron-volume-surface-area-formulas.html> | ||
|
||
:param edge: length of the edge of the dodecahedron | ||
:type edge: float | ||
:return: the volume of the dodecahedron as a float | ||
|
||
Tests: | ||
>>> dodecahedron_volume(5) | ||
957.8898700780791 | ||
>>> dodecahedron_volume(10) | ||
7663.118960624633 | ||
>>> dodecahedron_volume(-1) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Length must be a positive. | ||
""" | ||
|
||
if edge <= 0 or not isinstance(edge, int): | ||
raise ValueError("Length must be a positive.") | ||
|
||
volume = ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3) | ||
return volume | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
if __name__ == "__main__": | ||
shri30yans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
edge = 5 | ||
print("Dodecahedron edge:", edge) | ||
print("Surface area: ", dodecahedron_surface_area(edge=edge)) | ||
print("Volume: ", dodecahedron_volume(edge=edge)) | ||
shri30yans marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.