From faed05b2e30da65e10bfbf8c768bb34808a6a3a2 Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:51:41 +0530 Subject: [PATCH 01/10] Create potential_energy.py Finding the gravitational potential energy of an object with reference to the earth, by taking its mass and height above the ground as input --- physics/potential_energy.py | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 physics/potential_energy.py diff --git a/physics/potential_energy.py b/physics/potential_energy.py new file mode 100644 index 000000000000..2ef193279ef1 --- /dev/null +++ b/physics/potential_energy.py @@ -0,0 +1,61 @@ +from doctest import testmod +import scipy.constants as cons + +''' +Finding the gravitational potential energy of an object with reference +to the earth,by taking its mass and height above the ground as input + + +Description : Gravitational energy or gravitational potential energy +is the potential energy a massive object has in relation to another +massive object due to gravity. It is the potential energy associated +with the gravitational field, which is released (converted into +kinetic energy) when the objects fall towards each other. +Gravitational potential energy increases when two objects +are brought further apart. + +For two pairwise interacting point particles, the gravitational +potential energy U is given by +U=-GMm/R +where M and m are the masses of the two particles, R is the distance +between them, and G is the gravitational constant. +Close to the Earth's surface, the gravitational field is approximately +constant, and the gravitational potential energy of an object reduces to +U=mgh +where m is the object's mass, g=GM/R² is the gravity of Earth, and h is +the height of the object's center of mass above a chosen reference level. + + +Reference : "https://en.m.wikipedia.org/wiki/Gravitational_energy" +''' + + +def potential_energy(mass : float, height : float) -> float: +#function will accept mass and height as parameters and return potential energy + """ + >>> potential_energy(10,10) + 980.665 + >>> potential_energy(0,5) + 0.0 + >>> potential_energy(8,0) + 0.0 + >>> potential_energy(10,5) + 490.3325 + >>> potential_energy(0,0) + 0.0 + >>> potential_energy(2,8) + 156.9064 + >>> potential_energy(20,100) + 19613.3 + """ + if mass < 0: + raise ValueError('The mass of a body cannot be negative') + #handling of negative values of mass + if height < 0: + raise ValueError('The height above the ground cannot be negative') + #handling of negative values of height + return (mass*cons.g*height) + + +if __name__ == "__main__": + testmod(name = 'potential_energy') From 80156f5c602f5eb4b1705c0190c0282e2f71c2e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Oct 2022 12:23:45 +0000 Subject: [PATCH 02/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/potential_energy.py | 77 +++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index 2ef193279ef1..fe5eae15e129 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -1,7 +1,8 @@ -from doctest import testmod +from doctest import testmod + import scipy.constants as cons -''' +""" Finding the gravitational potential energy of an object with reference to the earth,by taking its mass and height above the ground as input @@ -9,53 +10,53 @@ Description : Gravitational energy or gravitational potential energy is the potential energy a massive object has in relation to another massive object due to gravity. It is the potential energy associated -with the gravitational field, which is released (converted into -kinetic energy) when the objects fall towards each other. -Gravitational potential energy increases when two objects +with the gravitational field, which is released (converted into +kinetic energy) when the objects fall towards each other. +Gravitational potential energy increases when two objects are brought further apart. -For two pairwise interacting point particles, the gravitational +For two pairwise interacting point particles, the gravitational potential energy U is given by U=-GMm/R -where M and m are the masses of the two particles, R is the distance +where M and m are the masses of the two particles, R is the distance between them, and G is the gravitational constant. -Close to the Earth's surface, the gravitational field is approximately +Close to the Earth's surface, the gravitational field is approximately constant, and the gravitational potential energy of an object reduces to U=mgh -where m is the object's mass, g=GM/R² is the gravity of Earth, and h is +where m is the object's mass, g=GM/R² is the gravity of Earth, and h is the height of the object's center of mass above a chosen reference level. Reference : "https://en.m.wikipedia.org/wiki/Gravitational_energy" -''' - - -def potential_energy(mass : float, height : float) -> float: -#function will accept mass and height as parameters and return potential energy - """ - >>> potential_energy(10,10) - 980.665 - >>> potential_energy(0,5) - 0.0 - >>> potential_energy(8,0) - 0.0 - >>> potential_energy(10,5) - 490.3325 - >>> potential_energy(0,0) - 0.0 - >>> potential_energy(2,8) - 156.9064 - >>> potential_energy(20,100) - 19613.3 - """ - if mass < 0: - raise ValueError('The mass of a body cannot be negative') - #handling of negative values of mass - if height < 0: - raise ValueError('The height above the ground cannot be negative') - #handling of negative values of height - return (mass*cons.g*height) +""" + + +def potential_energy(mass: float, height: float) -> float: + # function will accept mass and height as parameters and return potential energy + """ + >>> potential_energy(10,10) + 980.665 + >>> potential_energy(0,5) + 0.0 + >>> potential_energy(8,0) + 0.0 + >>> potential_energy(10,5) + 490.3325 + >>> potential_energy(0,0) + 0.0 + >>> potential_energy(2,8) + 156.9064 + >>> potential_energy(20,100) + 19613.3 + """ + if mass < 0: + raise ValueError("The mass of a body cannot be negative") + # handling of negative values of mass + if height < 0: + raise ValueError("The height above the ground cannot be negative") + # handling of negative values of height + return mass * cons.g * height if __name__ == "__main__": - testmod(name = 'potential_energy') + testmod(name="potential_energy") From d26d98ba328e1f67f9a22a85c2ac477eae397e63 Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Thu, 27 Oct 2022 16:41:26 +0530 Subject: [PATCH 03/10] Update physics/potential_energy.py Co-authored-by: Chris O <46587501+ChrisO345@users.noreply.github.com> --- physics/potential_energy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index fe5eae15e129..960c6df251fa 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -1,6 +1,6 @@ from doctest import testmod -import scipy.constants as cons +from scipy.constants import g """ Finding the gravitational potential energy of an object with reference From cb740a72d7fd002ffa76baebcdb398bfe9d15e7c Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Thu, 27 Oct 2022 16:41:55 +0530 Subject: [PATCH 04/10] Update physics/potential_energy.py Co-authored-by: Chris O <46587501+ChrisO345@users.noreply.github.com> --- physics/potential_energy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index 960c6df251fa..ff29e0a3e5be 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -55,7 +55,7 @@ def potential_energy(mass: float, height: float) -> float: if height < 0: raise ValueError("The height above the ground cannot be negative") # handling of negative values of height - return mass * cons.g * height + return mass * g * height if __name__ == "__main__": From 24ce9b8a5c49ebc418c9a68afac5cbd11b08a29e Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:13:58 +0530 Subject: [PATCH 05/10] Update physics/potential_energy.py Co-authored-by: Caeden Perelli-Harris --- physics/potential_energy.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index ff29e0a3e5be..e7e9abe40886 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -1,5 +1,3 @@ -from doctest import testmod - from scipy.constants import g """ From 908245d82f5540959ff0ed1ebadfb94fcab01ac8 Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:14:15 +0530 Subject: [PATCH 06/10] Update physics/potential_energy.py Co-authored-by: Caeden Perelli-Harris --- physics/potential_energy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index e7e9abe40886..12453249846b 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -24,7 +24,6 @@ where m is the object's mass, g=GM/R² is the gravity of Earth, and h is the height of the object's center of mass above a chosen reference level. - Reference : "https://en.m.wikipedia.org/wiki/Gravitational_energy" """ From 0553b78f41d5d39fe7c83124047f4ae2f49fc416 Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:15:06 +0530 Subject: [PATCH 07/10] Update physics/potential_energy.py Co-authored-by: Caeden Perelli-Harris --- physics/potential_energy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index 12453249846b..549ff50334aa 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -47,8 +47,8 @@ def potential_energy(mass: float, height: float) -> float: 19613.3 """ if mass < 0: - raise ValueError("The mass of a body cannot be negative") # handling of negative values of mass + raise ValueError("The mass of a body cannot be negative") if height < 0: raise ValueError("The height above the ground cannot be negative") # handling of negative values of height From 1d44b43c1d728b27427897354cda16338134dfad Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:15:27 +0530 Subject: [PATCH 08/10] Update physics/potential_energy.py Co-authored-by: Caeden Perelli-Harris --- physics/potential_energy.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index 549ff50334aa..bcd7e0bf111e 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -56,4 +56,6 @@ def potential_energy(mass: float, height: float) -> float: if __name__ == "__main__": + from doctest import testmod + testmod(name="potential_energy") From aaf171fb31db16f5bb0a085d38dbd92c7facac3e Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:15:35 +0530 Subject: [PATCH 09/10] Update physics/potential_energy.py Co-authored-by: Caeden Perelli-Harris --- physics/potential_energy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index bcd7e0bf111e..de5cdd5dcc54 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -50,8 +50,8 @@ def potential_energy(mass: float, height: float) -> float: # handling of negative values of mass raise ValueError("The mass of a body cannot be negative") if height < 0: - raise ValueError("The height above the ground cannot be negative") # handling of negative values of height + raise ValueError("The height above the ground cannot be negative") return mass * g * height From b3e4a0ac91e7739029aab905dcd8f89a88a985a9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:48:12 +0000 Subject: [PATCH 10/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/potential_energy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/potential_energy.py b/physics/potential_energy.py index de5cdd5dcc54..c6544f6f76d8 100644 --- a/physics/potential_energy.py +++ b/physics/potential_energy.py @@ -57,5 +57,5 @@ def potential_energy(mass: float, height: float) -> float: if __name__ == "__main__": from doctest import testmod - + testmod(name="potential_energy")