Skip to content
Merged
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1427fe3
avg and mps speed formulae added
Baron105 Oct 10, 2023
0608c40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
7457b25
avg and mps speed formulae added
Baron105 Oct 10, 2023
b1ef5a3
fixed_spacing
Baron105 Oct 10, 2023
c957bd7
.
Baron105 Oct 10, 2023
07502c8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
ead4f47
spacing
Baron105 Oct 10, 2023
c18b39d
.
Baron105 Oct 10, 2023
cb006c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
ab04734
ws
Baron105 Oct 10, 2023
69487f3
Merge branch 'master' of https://github.com/Baron105/Python
Baron105 Oct 10, 2023
6a741dc
added amicable numbers
Baron105 Oct 10, 2023
d13c09d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
18df9ba
Merge branch 'TheAlgorithms:master' into master
Baron105 Oct 10, 2023
63734b9
added amicable numbers
Baron105 Oct 10, 2023
aa5f176
descriptive
Baron105 Oct 10, 2023
9779c1a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
aa4d4e8
spacing
Baron105 Oct 10, 2023
7bb663f
Merge branch 'master' of https://github.com/Baron105/Python
Baron105 Oct 10, 2023
52c2cb8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
643958b
removed
Baron105 Oct 10, 2023
65f5851
Merge branch 'master' of https://github.com/Baron105/Python
Baron105 Oct 10, 2023
7f14ab9
Merge branch 'TheAlgorithms:master' into master
Baron105 Oct 12, 2023
c05ed7c
changed name of file and added code improvements
Baron105 Oct 12, 2023
886fb5d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 12, 2023
97b89cd
issues fixed due to pi
Baron105 Oct 12, 2023
a1c783a
Merge branch 'master' of https://github.com/Baron105/Python
Baron105 Oct 12, 2023
1c2b7b2
requested changes added
Baron105 Oct 12, 2023
5aa65b8
Merge branch 'TheAlgorithms:master' into master
Baron105 Oct 13, 2023
59e9c01
Merge branch 'TheAlgorithms:master' into master
Baron105 Oct 15, 2023
37cc5a4
added some doctests for exception handling, imported g from scipy and…
Baron105 Oct 15, 2023
cf56671
removed_scipy_import
Baron105 Oct 15, 2023
802a381
Update and rename archimedes_principle.py to archimedes_principle_of_…
cclauss Oct 15, 2023
208932d
Update archimedes_principle_of_buoyant_force.py
cclauss Oct 15, 2023
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
22 changes: 18 additions & 4 deletions physics/archimedes_principle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"""


# Acceleration Constant on Earth (unit m/s^2)
g = 9.80665
# Acceleration Constant on Earth (unit m/s^2) imported from scipy
from scipy.constants import g


def archimedes_principle(
Expand All @@ -30,13 +30,27 @@ def archimedes_principle(
4885.3
>>> archimedes_principle(fluid_density=997, volume=0.7)
6844.061035
>>> archimedes_principle(fluid_density=997, volume=-0.7)
Traceback (most recent call last):
...
ValueError: Impossible Object volume
>>> archimedes_principle(fluid_density=0, volume=0.7)
Traceback (most recent call last):
...
ValueError: Impossible fluid density
>>> archimedes_principle(fluid_density=997, volume=0.7, gravity=0)
0.0
>>> archimedes_principle(fluid_density=997, volume=0.7, gravity=-9.8)
Traceback (most recent call last):
...
ValueError: Impossible Gravity
"""

if fluid_density <= 0:
raise ValueError("Impossible fluid density")
if volume < 0:
if volume <= 0:
raise ValueError("Impossible Object volume")
if gravity <= 0:
if gravity < 0:
Copy link
Member

Choose a reason for hiding this comment

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

Please revert these changes. It is useful to be able to make theoretical calculations even if we are unable to reproduce those conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should I remove the tests as well or just make the signs as they were before?

Copy link
Member

Choose a reason for hiding this comment

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

The tests need to follow the code. It is OK to have the tests but their output must pass.

Copy link
Contributor Author

@Baron105 Baron105 Oct 15, 2023

Choose a reason for hiding this comment

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

The numerical tests are passing. Just added some more tests to see for when the inputs are invalid physically as in negative gravity, non positive volume and non positive density as they were already in the original code by the author.
These are also passing the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please check @cclauss

Copy link
Member

Choose a reason for hiding this comment

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

Dude! There are 215 pull requests open. Perhaps we will get to review this one.

raise ValueError("Impossible Gravity")

return fluid_density * gravity * volume
Expand Down