From 11404b7ed8b5ddf6ca0e66111177a79d3933106e Mon Sep 17 00:00:00 2001 From: SparshRastogi <75373475+SparshRastogi@users.noreply.github.com> Date: Tue, 25 Oct 2022 13:32:08 +0530 Subject: [PATCH 1/4] Create kinetic_energy.py Finding the kinetic energy of an object,by taking its mass and velocity as input --- physics/kinetic_energy.py | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 physics/kinetic_energy.py diff --git a/physics/kinetic_energy.py b/physics/kinetic_energy.py new file mode 100644 index 000000000000..8bdeec930158 --- /dev/null +++ b/physics/kinetic_energy.py @@ -0,0 +1,51 @@ +import doctest + + +''' + + + +Finding the kinetic energy of an object,by taking its mass and velocity as input + + +Description : In physics, the kinetic energy of an object is the energy that it possesses due to its motion. +It is defined as the work needed to accelerate a body of a given mass from rest to its stated velocity. +Having gained this energy during its acceleration, the body maintains this kinetic energy unless its speed changes. +The same amount of work is done by the body when decelerating from its current speed to a state of rest. +Formally, a kinetic energy is any term in a system's Lagrangian which includes a derivative with respect to time. + +In classical mechanics, the kinetic energy of a non-rotating object of mass m traveling at a speed v is ½mv². +In relativistic mechanics, this is a good approximation only when v is much less than the speed of light. +The standard unit of kinetic energy is the joule, while the English unit of kinetic energy is the foot-pound. + +Reference : "https://en.m.wikipedia.org/wiki/Kinetic_energy" + +''' + + +def kinetic_energy(mass : float, velocity : float) -> float: #function will accept mass and velocity as parameters and return kinetic energy + """ + >>> kinetic_energy(10,10) + 500.0 + >>> kinetic_energy(0,10) + 0.0 + >>> kinetic_energy(10,0) + 0.0 + >>> kinetic_energy(20,-20) + 4000.0 + >>> kinetic_energy(0,0) + 0.0 + >>> kinetic_energy(2,2) + 4.0 + >>> kinetic_energy(100,100) + 500000.0 + """ + if mass < 0: + raise ValueError('The mass of a body cannot be negative') + elif mass >= 0: + ke = 0.5 * mass *abs(velocity) * abs(velocity) + return ke + + +if __name__ == "__main__": + doctest.testmod(name = 'kinetic_energy',verbose = True) From 558fb6891813fd27e021126f2a3729bca932bb7f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 08:04:56 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/kinetic_energy.py | 65 ++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/physics/kinetic_energy.py b/physics/kinetic_energy.py index 8bdeec930158..b85bd8f78262 100644 --- a/physics/kinetic_energy.py +++ b/physics/kinetic_energy.py @@ -1,7 +1,6 @@ import doctest - -''' +""" @@ -9,10 +8,10 @@ Description : In physics, the kinetic energy of an object is the energy that it possesses due to its motion. -It is defined as the work needed to accelerate a body of a given mass from rest to its stated velocity. -Having gained this energy during its acceleration, the body maintains this kinetic energy unless its speed changes. -The same amount of work is done by the body when decelerating from its current speed to a state of rest. -Formally, a kinetic energy is any term in a system's Lagrangian which includes a derivative with respect to time. +It is defined as the work needed to accelerate a body of a given mass from rest to its stated velocity. +Having gained this energy during its acceleration, the body maintains this kinetic energy unless its speed changes. +The same amount of work is done by the body when decelerating from its current speed to a state of rest. +Formally, a kinetic energy is any term in a system's Lagrangian which includes a derivative with respect to time. In classical mechanics, the kinetic energy of a non-rotating object of mass m traveling at a speed v is ½mv². In relativistic mechanics, this is a good approximation only when v is much less than the speed of light. @@ -20,32 +19,34 @@ Reference : "https://en.m.wikipedia.org/wiki/Kinetic_energy" -''' - - -def kinetic_energy(mass : float, velocity : float) -> float: #function will accept mass and velocity as parameters and return kinetic energy - """ - >>> kinetic_energy(10,10) - 500.0 - >>> kinetic_energy(0,10) - 0.0 - >>> kinetic_energy(10,0) - 0.0 - >>> kinetic_energy(20,-20) - 4000.0 - >>> kinetic_energy(0,0) - 0.0 - >>> kinetic_energy(2,2) - 4.0 - >>> kinetic_energy(100,100) - 500000.0 - """ - if mass < 0: - raise ValueError('The mass of a body cannot be negative') - elif mass >= 0: - ke = 0.5 * mass *abs(velocity) * abs(velocity) - return ke +""" + + +def kinetic_energy( + mass: float, velocity: float +) -> float: # function will accept mass and velocity as parameters and return kinetic energy + """ + >>> kinetic_energy(10,10) + 500.0 + >>> kinetic_energy(0,10) + 0.0 + >>> kinetic_energy(10,0) + 0.0 + >>> kinetic_energy(20,-20) + 4000.0 + >>> kinetic_energy(0,0) + 0.0 + >>> kinetic_energy(2,2) + 4.0 + >>> kinetic_energy(100,100) + 500000.0 + """ + if mass < 0: + raise ValueError("The mass of a body cannot be negative") + elif mass >= 0: + ke = 0.5 * mass * abs(velocity) * abs(velocity) + return ke if __name__ == "__main__": - doctest.testmod(name = 'kinetic_energy',verbose = True) + doctest.testmod(name="kinetic_energy", verbose=True) From 410f682c12df5a4b6c0b65fc8510fcfa3f925012 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 25 Oct 2022 21:35:55 +0200 Subject: [PATCH 3/4] Update kinetic_energy.py --- physics/kinetic_energy.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/physics/kinetic_energy.py b/physics/kinetic_energy.py index b85bd8f78262..b5b0cc24b9e7 100644 --- a/physics/kinetic_energy.py +++ b/physics/kinetic_energy.py @@ -1,11 +1,5 @@ -import doctest - """ - - - -Finding the kinetic energy of an object,by taking its mass and velocity as input - +Find the kinetic energy of an object, give its mass and velocity Description : In physics, the kinetic energy of an object is the energy that it possesses due to its motion. It is defined as the work needed to accelerate a body of a given mass from rest to its stated velocity. @@ -17,14 +11,11 @@ In relativistic mechanics, this is a good approximation only when v is much less than the speed of light. The standard unit of kinetic energy is the joule, while the English unit of kinetic energy is the foot-pound. -Reference : "https://en.m.wikipedia.org/wiki/Kinetic_energy" - +Reference : https://en.m.wikipedia.org/wiki/Kinetic_energy """ -def kinetic_energy( - mass: float, velocity: float -) -> float: # function will accept mass and velocity as parameters and return kinetic energy +def kinetic_energy(mass: float, velocity: float) -> float: """ >>> kinetic_energy(10,10) 500.0 @@ -43,10 +34,10 @@ def kinetic_energy( """ if mass < 0: raise ValueError("The mass of a body cannot be negative") - elif mass >= 0: - ke = 0.5 * mass * abs(velocity) * abs(velocity) - return ke + return 0.5 * mass * abs(velocity) * abs(velocity) if __name__ == "__main__": - doctest.testmod(name="kinetic_energy", verbose=True) + import doctest + + doctest.testmod(verbose=True) From 764ba4b568f680bd4f4911a798dfae44aaf2cef8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 25 Oct 2022 21:40:04 +0200 Subject: [PATCH 4/4] Update kinetic_energy.py --- physics/kinetic_energy.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/physics/kinetic_energy.py b/physics/kinetic_energy.py index b5b0cc24b9e7..535ffc219251 100644 --- a/physics/kinetic_energy.py +++ b/physics/kinetic_energy.py @@ -1,15 +1,17 @@ """ Find the kinetic energy of an object, give its mass and velocity - -Description : In physics, the kinetic energy of an object is the energy that it possesses due to its motion. -It is defined as the work needed to accelerate a body of a given mass from rest to its stated velocity. -Having gained this energy during its acceleration, the body maintains this kinetic energy unless its speed changes. -The same amount of work is done by the body when decelerating from its current speed to a state of rest. -Formally, a kinetic energy is any term in a system's Lagrangian which includes a derivative with respect to time. - -In classical mechanics, the kinetic energy of a non-rotating object of mass m traveling at a speed v is ½mv². -In relativistic mechanics, this is a good approximation only when v is much less than the speed of light. -The standard unit of kinetic energy is the joule, while the English unit of kinetic energy is the foot-pound. +Description : In physics, the kinetic energy of an object is the energy that it +possesses due to its motion. It is defined as the work needed to accelerate a body of a +given mass from rest to its stated velocity. Having gained this energy during its +acceleration, the body maintains this kinetic energy unless its speed changes. The same +amount of work is done by the body when decelerating from its current speed to a state +of rest. Formally, a kinetic energy is any term in a system's Lagrangian which includes +a derivative with respect to time. + +In classical mechanics, the kinetic energy of a non-rotating object of mass m traveling +at a speed v is ½mv². In relativistic mechanics, this is a good approximation only when +v is much less than the speed of light. The standard unit of kinetic energy is the +joule, while the English unit of kinetic energy is the foot-pound. Reference : https://en.m.wikipedia.org/wiki/Kinetic_energy """ @@ -17,6 +19,8 @@ def kinetic_energy(mass: float, velocity: float) -> float: """ + The kinetic energy of a non-rotating object of mass m traveling at a speed v is ½mv² + >>> kinetic_energy(10,10) 500.0 >>> kinetic_energy(0,10)