From be3aacb6637ca6c059094363f7b9f8c5dd92958d Mon Sep 17 00:00:00 2001 From: autobotx343 Date: Sun, 7 Jun 2026 22:26:39 -0400 Subject: [PATCH 01/12] Module for Inelastic and Elastic Collisions --- physics/collisions.py | 127 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 physics/collisions.py diff --git a/physics/collisions.py b/physics/collisions.py new file mode 100644 index 000000000000..c39b3154761a --- /dev/null +++ b/physics/collisions.py @@ -0,0 +1,127 @@ +""" +Finding the type of collision and calculating final velocities after collisions are fundamental concepts in physics. +This module provides functions to compute the final velocities of two masses after both inelastic and elastic collisions, +as well as a function to determine the type of collision based on initial and final velocities. + +Description: Collisions in physics refers to the interaction between two masses when they collide head-on. There are 2 types of +collisions: inelastic and elastic. In an inelastic collision, the two masses stick together and move with a common velocity +after the collision. In an elastic collision, both momentum and kinetic energy are conserved, and the masses bounce off each other without sticking together. +Momentum is the product of mass and velocity, while kinetic energy is given by the formula (1/2) * mass * velocity^2. +The type of collision can be determined by comparing the initial and final momentum and kinetic energy of the system. + +Reference: https://en.wikipedia.org/wiki/Collision +""" + +def inelastic_collisions(mass1 :float, + mass2 :float, + velocity1 :float, + velocity2 :float + ) -> float : + """Calculate final velocity after a perfectly inelastic collision. + + The two objects stick together and share a common final velocity. + + Parameters: + mass1: Mass of the first object. + mass2: Mass of the second object. + velocity1: Initial velocity of the first object. + velocity2: Initial velocity of the second object. + + Returns: + The final combined velocity of the two objects. + + Examples: + >>> inelastic_collisions(2.0, 3.0, 5.0, 6.0) + 5.6 + >>> inelastic_collisions(9.0, 8.1, -3.2, 3.1) + -0.22 + """ + initial_momentum = ((mass1 * velocity1) + (mass2 * velocity2)) + total_mass = (mass2 + mass1) + final_velocity = round((initial_momentum/total_mass), 2) + + return final_velocity + + +def elastic_collisions(mass1 :float, + mass2 :float, + velocity1 :float, + velocity2 :float + ) -> str : + """Calculate final velocities after a perfectly elastic collision. + + This assumes the collision is head-on and conserves both momentum and kinetic energy. + + Parameters: + mass1: Mass of the first object. + mass2: Mass of the second object. + velocity1: Initial velocity of the first object. + velocity2: Initial velocity of the second object. + + Returns: + A formatted string containing the final velocities of both objects. + + Examples: + >>> elastic_collisions(1.0, 2.0, -3.0, -1.0) + '-0.34 ; -2.34' + >>> elastic_collisions(9.0, 8.1, -3.2, 3.1) + '2.76 ; -3.54' + """ + com_velocity = inelastic_collisions(mass1, mass2, velocity1, velocity2) + initial_velocities = [velocity1, velocity2] + final_velocities = [] + + for vel in initial_velocities: + new_vel = -1 * (vel - com_velocity) + final_vel = com_velocity + new_vel + final_velocities.append(round(final_vel, 2)) + + return f'{final_velocities[0]} ; {final_velocities[1]}' + + +def type_collision(mass1 :float, + mass2 :float, + velocity_initial1 :float, + velocity_initial2 :float, + velocity_final1 :float, + velocity_final2 :float + ) -> str : + """Determine the collision type from initial and final velocities. + + Compares initial and final momentum and kinetic energy to classify the collision. + + Parameters: + mass1: Mass of the first object. + mass2: Mass of the second object. + velocity_initial1: Initial velocity of the first object. + velocity_initial2: Initial velocity of the second object. + velocity_final1: Final velocity of the first object. + velocity_final2: Final velocity of the second object. + + Returns: + A string describing the collision type. + + Examples: + >>> type_collision(1.0, 1.0, 2.0, 3.0, 2.0, 3.0) + 'Perfectly Elastic Collision' + >>> type_collision(1.0, 1.0, 2.0, 3.0, 2.5, 2.5) + 'Perfectly Inelastic Collision' + >>> type_collision(1.0, 1.0, 2.0, 3.0, 0.0, 0.0) + 'Inelastic Collision' + """ + momentum_initial = ((mass1 * velocity_initial1) + (mass2 * velocity_initial2)) + momentum_final = ((mass1 * velocity_final1) + (mass2 * velocity_final2)) + kinetic_initial = 0.5 * ((mass1 * velocity_initial1**2) + (mass2 * velocity_initial2**2)) + kinetic_final = 0.5 * ((mass1 * velocity_final1**2) + (mass2 * velocity_final2**2)) + + if kinetic_final == kinetic_initial and momentum_initial == momentum_final: + return f'Perfectly Elastic Collision' + elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + return f'Perfectly Inelastic Collision' + else: + return f'Inelastic Collision' + + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file From d56039a03debb385bcbf822d9a26c24ce3d65f4c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Jun 2026 02:31:49 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/collisions.py | 73 ++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index c39b3154761a..184bbca6dd40 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -1,22 +1,21 @@ """ -Finding the type of collision and calculating final velocities after collisions are fundamental concepts in physics. -This module provides functions to compute the final velocities of two masses after both inelastic and elastic collisions, +Finding the type of collision and calculating final velocities after collisions are fundamental concepts in physics. +This module provides functions to compute the final velocities of two masses after both inelastic and elastic collisions, as well as a function to determine the type of collision based on initial and final velocities. Description: Collisions in physics refers to the interaction between two masses when they collide head-on. There are 2 types of -collisions: inelastic and elastic. In an inelastic collision, the two masses stick together and move with a common velocity +collisions: inelastic and elastic. In an inelastic collision, the two masses stick together and move with a common velocity after the collision. In an elastic collision, both momentum and kinetic energy are conserved, and the masses bounce off each other without sticking together. -Momentum is the product of mass and velocity, while kinetic energy is given by the formula (1/2) * mass * velocity^2. +Momentum is the product of mass and velocity, while kinetic energy is given by the formula (1/2) * mass * velocity^2. The type of collision can be determined by comparing the initial and final momentum and kinetic energy of the system. Reference: https://en.wikipedia.org/wiki/Collision """ -def inelastic_collisions(mass1 :float, - mass2 :float, - velocity1 :float, - velocity2 :float - ) -> float : + +def inelastic_collisions( + mass1: float, mass2: float, velocity1: float, velocity2: float +) -> float: """Calculate final velocity after a perfectly inelastic collision. The two objects stick together and share a common final velocity. @@ -36,18 +35,16 @@ def inelastic_collisions(mass1 :float, >>> inelastic_collisions(9.0, 8.1, -3.2, 3.1) -0.22 """ - initial_momentum = ((mass1 * velocity1) + (mass2 * velocity2)) - total_mass = (mass2 + mass1) - final_velocity = round((initial_momentum/total_mass), 2) - + initial_momentum = (mass1 * velocity1) + (mass2 * velocity2) + total_mass = mass2 + mass1 + final_velocity = round((initial_momentum / total_mass), 2) + return final_velocity -def elastic_collisions(mass1 :float, - mass2 :float, - velocity1 :float, - velocity2 :float - ) -> str : +def elastic_collisions( + mass1: float, mass2: float, velocity1: float, velocity2: float +) -> str: """Calculate final velocities after a perfectly elastic collision. This assumes the collision is head-on and conserves both momentum and kinetic energy. @@ -68,24 +65,25 @@ def elastic_collisions(mass1 :float, '2.76 ; -3.54' """ com_velocity = inelastic_collisions(mass1, mass2, velocity1, velocity2) - initial_velocities = [velocity1, velocity2] + initial_velocities = [velocity1, velocity2] final_velocities = [] for vel in initial_velocities: new_vel = -1 * (vel - com_velocity) final_vel = com_velocity + new_vel final_velocities.append(round(final_vel, 2)) - - return f'{final_velocities[0]} ; {final_velocities[1]}' + return f"{final_velocities[0]} ; {final_velocities[1]}" -def type_collision(mass1 :float, - mass2 :float, - velocity_initial1 :float, - velocity_initial2 :float, - velocity_final1 :float, - velocity_final2 :float - ) -> str : + +def type_collision( + mass1: float, + mass2: float, + velocity_initial1: float, + velocity_initial2: float, + velocity_final1: float, + velocity_final2: float, +) -> str: """Determine the collision type from initial and final velocities. Compares initial and final momentum and kinetic energy to classify the collision. @@ -109,19 +107,22 @@ def type_collision(mass1 :float, >>> type_collision(1.0, 1.0, 2.0, 3.0, 0.0, 0.0) 'Inelastic Collision' """ - momentum_initial = ((mass1 * velocity_initial1) + (mass2 * velocity_initial2)) - momentum_final = ((mass1 * velocity_final1) + (mass2 * velocity_final2)) - kinetic_initial = 0.5 * ((mass1 * velocity_initial1**2) + (mass2 * velocity_initial2**2)) + momentum_initial = (mass1 * velocity_initial1) + (mass2 * velocity_initial2) + momentum_final = (mass1 * velocity_final1) + (mass2 * velocity_final2) + kinetic_initial = 0.5 * ( + (mass1 * velocity_initial1**2) + (mass2 * velocity_initial2**2) + ) kinetic_final = 0.5 * ((mass1 * velocity_final1**2) + (mass2 * velocity_final2**2)) if kinetic_final == kinetic_initial and momentum_initial == momentum_final: - return f'Perfectly Elastic Collision' - elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: - return f'Perfectly Inelastic Collision' + return f"Perfectly Elastic Collision" + elif not (kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + return f"Perfectly Inelastic Collision" else: - return f'Inelastic Collision' + return f"Inelastic Collision" if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + + doctest.testmod() From 63c4a27ff15f23590ac07833d9dd9aee3538c438 Mon Sep 17 00:00:00 2001 From: autobotx343 Date: Tue, 9 Jun 2026 16:02:59 -0400 Subject: [PATCH 03/12] fixed error to push to main --- physics/collisions.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index c39b3154761a..8ba3da99c2fb 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -1,13 +1,15 @@ """ -Finding the type of collision and calculating final velocities after collisions are fundamental concepts in physics. -This module provides functions to compute the final velocities of two masses after both inelastic and elastic collisions, -as well as a function to determine the type of collision based on initial and final velocities. - -Description: Collisions in physics refers to the interaction between two masses when they collide head-on. There are 2 types of -collisions: inelastic and elastic. In an inelastic collision, the two masses stick together and move with a common velocity -after the collision. In an elastic collision, both momentum and kinetic energy are conserved, and the masses bounce off each other without sticking together. -Momentum is the product of mass and velocity, while kinetic energy is given by the formula (1/2) * mass * velocity^2. -The type of collision can be determined by comparing the initial and final momentum and kinetic energy of the system. +Finding collision types and final velocities is key in physics. +This module computes final velocities for inelastic and elastic collisions. +It also identifies the collision type from initial and final velocities. + +Description: Collisions happen when two masses interact head-on. +There are two types: inelastic and elastic. In inelastic collisions, the +masses stick together and share one final velocity. In elastic collisions, +momentum and kinetic energy stay conserved, and the masses rebound. +Momentum is mass times velocity, and kinetic energy is 1/2 mv^2. +The type of collision can be found by comparing the system's initial and +final momentum and kinetic energy. Reference: https://en.wikipedia.org/wiki/Collision """ @@ -50,7 +52,7 @@ def elastic_collisions(mass1 :float, ) -> str : """Calculate final velocities after a perfectly elastic collision. - This assumes the collision is head-on and conserves both momentum and kinetic energy. + The collision is head-on and conserves both momentum and kinetic energy. Parameters: mass1: Mass of the first object. @@ -115,11 +117,11 @@ def type_collision(mass1 :float, kinetic_final = 0.5 * ((mass1 * velocity_final1**2) + (mass2 * velocity_final2**2)) if kinetic_final == kinetic_initial and momentum_initial == momentum_final: - return f'Perfectly Elastic Collision' + return 'Perfectly Elastic Collision' elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: - return f'Perfectly Inelastic Collision' + return 'Perfectly Inelastic Collision' else: - return f'Inelastic Collision' + return 'Inelastic Collision' if __name__ == "__main__": From 809da5249b7298ad7814a76b47b878acb29210c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jun 2026 20:04:54 +0000 Subject: [PATCH 04/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/collisions.py | 65 ++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index 8ba3da99c2fb..1b9c5af50f3c 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -14,11 +14,10 @@ Reference: https://en.wikipedia.org/wiki/Collision """ -def inelastic_collisions(mass1 :float, - mass2 :float, - velocity1 :float, - velocity2 :float - ) -> float : + +def inelastic_collisions( + mass1: float, mass2: float, velocity1: float, velocity2: float +) -> float: """Calculate final velocity after a perfectly inelastic collision. The two objects stick together and share a common final velocity. @@ -38,18 +37,16 @@ def inelastic_collisions(mass1 :float, >>> inelastic_collisions(9.0, 8.1, -3.2, 3.1) -0.22 """ - initial_momentum = ((mass1 * velocity1) + (mass2 * velocity2)) - total_mass = (mass2 + mass1) - final_velocity = round((initial_momentum/total_mass), 2) - + initial_momentum = (mass1 * velocity1) + (mass2 * velocity2) + total_mass = mass2 + mass1 + final_velocity = round((initial_momentum / total_mass), 2) + return final_velocity -def elastic_collisions(mass1 :float, - mass2 :float, - velocity1 :float, - velocity2 :float - ) -> str : +def elastic_collisions( + mass1: float, mass2: float, velocity1: float, velocity2: float +) -> str: """Calculate final velocities after a perfectly elastic collision. The collision is head-on and conserves both momentum and kinetic energy. @@ -70,24 +67,25 @@ def elastic_collisions(mass1 :float, '2.76 ; -3.54' """ com_velocity = inelastic_collisions(mass1, mass2, velocity1, velocity2) - initial_velocities = [velocity1, velocity2] + initial_velocities = [velocity1, velocity2] final_velocities = [] for vel in initial_velocities: new_vel = -1 * (vel - com_velocity) final_vel = com_velocity + new_vel final_velocities.append(round(final_vel, 2)) - - return f'{final_velocities[0]} ; {final_velocities[1]}' + return f"{final_velocities[0]} ; {final_velocities[1]}" -def type_collision(mass1 :float, - mass2 :float, - velocity_initial1 :float, - velocity_initial2 :float, - velocity_final1 :float, - velocity_final2 :float - ) -> str : + +def type_collision( + mass1: float, + mass2: float, + velocity_initial1: float, + velocity_initial2: float, + velocity_final1: float, + velocity_final2: float, +) -> str: """Determine the collision type from initial and final velocities. Compares initial and final momentum and kinetic energy to classify the collision. @@ -111,19 +109,22 @@ def type_collision(mass1 :float, >>> type_collision(1.0, 1.0, 2.0, 3.0, 0.0, 0.0) 'Inelastic Collision' """ - momentum_initial = ((mass1 * velocity_initial1) + (mass2 * velocity_initial2)) - momentum_final = ((mass1 * velocity_final1) + (mass2 * velocity_final2)) - kinetic_initial = 0.5 * ((mass1 * velocity_initial1**2) + (mass2 * velocity_initial2**2)) + momentum_initial = (mass1 * velocity_initial1) + (mass2 * velocity_initial2) + momentum_final = (mass1 * velocity_final1) + (mass2 * velocity_final2) + kinetic_initial = 0.5 * ( + (mass1 * velocity_initial1**2) + (mass2 * velocity_initial2**2) + ) kinetic_final = 0.5 * ((mass1 * velocity_final1**2) + (mass2 * velocity_final2**2)) if kinetic_final == kinetic_initial and momentum_initial == momentum_final: - return 'Perfectly Elastic Collision' - elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: - return 'Perfectly Inelastic Collision' + return "Perfectly Elastic Collision" + elif not (kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + return "Perfectly Inelastic Collision" else: - return 'Inelastic Collision' + return "Inelastic Collision" if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + + doctest.testmod() From 27e87016b7c6b659ddca8264325cc465a22e4b15 Mon Sep 17 00:00:00 2001 From: autobotx343 Date: Tue, 9 Jun 2026 16:18:22 -0400 Subject: [PATCH 05/12] ruff changes --- physics/collisions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/collisions.py b/physics/collisions.py index 8ba3da99c2fb..ca219e2dfa09 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -118,7 +118,7 @@ def type_collision(mass1 :float, if kinetic_final == kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Elastic Collision' - elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + elif kinetic_final != kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Inelastic Collision' else: return 'Inelastic Collision' From 8fee16789e90db3cd6f599f9d972552bf24dbad6 Mon Sep 17 00:00:00 2001 From: autobotx343 Date: Tue, 9 Jun 2026 16:21:23 -0400 Subject: [PATCH 06/12] ruff changes --- physics/collisions.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index 6234afc73adf..bd6155058fbf 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -1,15 +1,15 @@ """ -Finding collision types and final velocities is key in physics. +Collision types and final velocities are central to physics. This module computes final velocities for inelastic and elastic collisions. -It also identifies the collision type from initial and final velocities. +It also classifies the collision type from initial and final velocities. Description: Collisions happen when two masses interact head-on. There are two types: inelastic and elastic. In inelastic collisions, the masses stick together and share one final velocity. In elastic collisions, -momentum and kinetic energy stay conserved, and the masses rebound. -Momentum is mass times velocity, and kinetic energy is 1/2 mv^2. -The type of collision can be found by comparing the system's initial and -final momentum and kinetic energy. +momentum and kinetic energy are conserved, and masses rebound. +Momentum is mass times velocity; kinetic energy is 1/2 mv^2. +The collision type comes from comparing initial and final momentum and +kinetic energy of the system. Reference: https://en.wikipedia.org/wiki/Collision """ @@ -118,7 +118,7 @@ def type_collision( if kinetic_final == kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Elastic Collision' - elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + elif kinetic_final != kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Inelastic Collision' else: return "Inelastic Collision" From 45d51d9accc9d55fa5698c626bcdeb652e50aa8c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jun 2026 20:21:43 +0000 Subject: [PATCH 07/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/collisions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index bd6155058fbf..056a56ea5331 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -117,9 +117,9 @@ def type_collision( kinetic_final = 0.5 * ((mass1 * velocity_final1**2) + (mass2 * velocity_final2**2)) if kinetic_final == kinetic_initial and momentum_initial == momentum_final: - return 'Perfectly Elastic Collision' + return "Perfectly Elastic Collision" elif kinetic_final != kinetic_initial and momentum_initial == momentum_final: - return 'Perfectly Inelastic Collision' + return "Perfectly Inelastic Collision" else: return "Inelastic Collision" From 67e02185f05782eb769b8c227aec4b21b50c56c2 Mon Sep 17 00:00:00 2001 From: autobotx343 Date: Tue, 9 Jun 2026 16:02:59 -0400 Subject: [PATCH 08/12] fixed error to push to main --- physics/collisions.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index 184bbca6dd40..9a1e30f48182 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -1,13 +1,15 @@ """ -Finding the type of collision and calculating final velocities after collisions are fundamental concepts in physics. -This module provides functions to compute the final velocities of two masses after both inelastic and elastic collisions, -as well as a function to determine the type of collision based on initial and final velocities. - -Description: Collisions in physics refers to the interaction between two masses when they collide head-on. There are 2 types of -collisions: inelastic and elastic. In an inelastic collision, the two masses stick together and move with a common velocity -after the collision. In an elastic collision, both momentum and kinetic energy are conserved, and the masses bounce off each other without sticking together. -Momentum is the product of mass and velocity, while kinetic energy is given by the formula (1/2) * mass * velocity^2. -The type of collision can be determined by comparing the initial and final momentum and kinetic energy of the system. +Finding collision types and final velocities is key in physics. +This module computes final velocities for inelastic and elastic collisions. +It also identifies the collision type from initial and final velocities. + +Description: Collisions happen when two masses interact head-on. +There are two types: inelastic and elastic. In inelastic collisions, the +masses stick together and share one final velocity. In elastic collisions, +momentum and kinetic energy stay conserved, and the masses rebound. +Momentum is mass times velocity, and kinetic energy is 1/2 mv^2. +The type of collision can be found by comparing the system's initial and +final momentum and kinetic energy. Reference: https://en.wikipedia.org/wiki/Collision """ @@ -47,7 +49,7 @@ def elastic_collisions( ) -> str: """Calculate final velocities after a perfectly elastic collision. - This assumes the collision is head-on and conserves both momentum and kinetic energy. + The collision is head-on and conserves both momentum and kinetic energy. Parameters: mass1: Mass of the first object. @@ -115,11 +117,11 @@ def type_collision( kinetic_final = 0.5 * ((mass1 * velocity_final1**2) + (mass2 * velocity_final2**2)) if kinetic_final == kinetic_initial and momentum_initial == momentum_final: - return f"Perfectly Elastic Collision" - elif not (kinetic_final == kinetic_initial) and momentum_initial == momentum_final: - return f"Perfectly Inelastic Collision" + return 'Perfectly Elastic Collision' + elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + return 'Perfectly Inelastic Collision' else: - return f"Inelastic Collision" + return 'Inelastic Collision' if __name__ == "__main__": From 5aa391061a145b27157f34d492fe041c95d18e0f Mon Sep 17 00:00:00 2001 From: autobotx343 Date: Tue, 9 Jun 2026 16:18:22 -0400 Subject: [PATCH 09/12] ruff changes --- physics/collisions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/collisions.py b/physics/collisions.py index 9a1e30f48182..f9eea6a991ec 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -118,7 +118,7 @@ def type_collision( if kinetic_final == kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Elastic Collision' - elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + elif kinetic_final != kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Inelastic Collision' else: return 'Inelastic Collision' From 8864a1f8c5f4aa679e9ed6fe5c091e1827d7bb70 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jun 2026 20:04:54 +0000 Subject: [PATCH 10/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/collisions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index f9eea6a991ec..53095214a1f0 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -118,13 +118,15 @@ def type_collision( if kinetic_final == kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Elastic Collision' - elif kinetic_final != kinetic_initial and momentum_initial == momentum_final: + elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: return 'Perfectly Inelastic Collision' else: - return 'Inelastic Collision' + return "Inelastic Collision" if __name__ == "__main__": import doctest + doctest.testmod() + From d1ce6247cbe334e333aba354b16376dbc5abb67e Mon Sep 17 00:00:00 2001 From: autobotx343 Date: Tue, 9 Jun 2026 16:21:23 -0400 Subject: [PATCH 11/12] ruff changes --- physics/collisions.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index 53095214a1f0..39b7cb7d1bbb 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -1,15 +1,15 @@ """ -Finding collision types and final velocities is key in physics. +Collision types and final velocities are central to physics. This module computes final velocities for inelastic and elastic collisions. -It also identifies the collision type from initial and final velocities. +It also classifies the collision type from initial and final velocities. Description: Collisions happen when two masses interact head-on. There are two types: inelastic and elastic. In inelastic collisions, the masses stick together and share one final velocity. In elastic collisions, -momentum and kinetic energy stay conserved, and the masses rebound. -Momentum is mass times velocity, and kinetic energy is 1/2 mv^2. -The type of collision can be found by comparing the system's initial and -final momentum and kinetic energy. +momentum and kinetic energy are conserved, and masses rebound. +Momentum is mass times velocity; kinetic energy is 1/2 mv^2. +The collision type comes from comparing initial and final momentum and +kinetic energy of the system. Reference: https://en.wikipedia.org/wiki/Collision """ @@ -118,7 +118,7 @@ def type_collision( if kinetic_final == kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Elastic Collision' - elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + elif kinetic_final != kinetic_initial and momentum_initial == momentum_final: return 'Perfectly Inelastic Collision' else: return "Inelastic Collision" From befc37952273fbc591e584ccb848a99bee7733b9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 10 Jun 2026 00:41:30 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/collisions.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/physics/collisions.py b/physics/collisions.py index 3b57ee96ba35..813e9f12d51c 100644 --- a/physics/collisions.py +++ b/physics/collisions.py @@ -117,13 +117,14 @@ def type_collision( kinetic_final = 0.5 * ((mass1 * velocity_final1**2) + (mass2 * velocity_final2**2)) if kinetic_final == kinetic_initial and momentum_initial == momentum_final: - return f'Perfectly Elastic Collision' - elif not(kinetic_final == kinetic_initial) and momentum_initial == momentum_final: - return f'Perfectly Inelastic Collision' + return f"Perfectly Elastic Collision" + elif not (kinetic_final == kinetic_initial) and momentum_initial == momentum_final: + return f"Perfectly Inelastic Collision" else: return "Inelastic Collision" if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + + doctest.testmod()