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

Added newtons_second_law_of_motion.py #5474

Merged
merged 1 commit into from Nov 4, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,81 @@
"""
Description :
Newton's second law of motion pertains to the behavior of objects for which
all existing forces are not balanced.
The second law states that the acceleration of an object is dependent upon two variables
- the net force acting upon the object and the mass of the object.
The acceleration of an object depends directly
upon the net force acting upon the object,
and inversely upon the mass of the object.
As the force acting upon an object is increased,
the acceleration of the object is increased.
As the mass of an object is increased, the acceleration of the object is decreased.
Source: https://www.physicsclassroom.com/class/newtlaws/Lesson-3/Newton-s-Second-Law
Formulation: Fnet = m • a
Diagrammatic Explanation:
Forces are unbalanced
|
|
|
V
There is acceleration
/\
/ \
/ \
/ \
/ \
/ \
/ \
__________________ ____ ________________
|The acceleration | |The acceleration |
|depends directly | |depends inversely |
|on the net Force | |upon the object's |
|_________________| |mass_______________|
Units:
1 Newton = 1 kg X meters / (seconds^2)
How to use?
Inputs:
___________________________________________________
|Name | Units | Type |
|-------------|-------------------------|-----------|
|mass | (in kgs) | float |
|-------------|-------------------------|-----------|
|acceleration | (in meters/(seconds^2)) | float |
|_____________|_________________________|___________|
Output:
___________________________________________________
|Name | Units | Type |
|-------------|-------------------------|-----------|
|force | (in Newtons) | float |
|_____________|_________________________|___________|
"""


def newtons_second_law_of_motion(mass: float, acceleration: float) -> float:
"""
>>> newtons_second_law_of_motion(10, 10)
100
>>> newtons_second_law_of_motion(2.0, 1)
2.0
"""
force = float()
try:
force = mass * acceleration
This conversation was marked as resolved by poyea

This comment has been minimized.

@L3str4nge

L3str4nge Oct 22, 2021
Member

how about a mass < 0? :D

This comment has been minimized.

@divyesh1099

divyesh1099 Oct 22, 2021
Author Contributor

how about a mass < 0? :D

Sir that will not be possible, how can mass be negative sir 😅

This comment has been minimized.

@poyea

poyea Oct 26, 2021
Member

Yes it's not possible, so we may handle it in the code

This comment has been minimized.

@poyea

poyea Nov 3, 2021
Member

@divyesh1099 Could you handle this and add a few more test cases?

This comment has been minimized.

@divyesh1099

divyesh1099 Nov 3, 2021
Author Contributor

@divyesh1099 Could you handle this and add a few more test cases?

Yes sir I can. I'll do it asap

except Exception:
return -0.0
return force


if __name__ == "__main__":
import doctest

# run doctest
doctest.testmod()

# demo
mass = 12.5
acceleration = 10
force = newtons_second_law_of_motion(mass, acceleration)
print("The force is ", force, "N")
Added newtons_second_law_of_motion.py by divyesh1099 · Pull Request #5474 · TheAlgorithms/Python · GitHub
24 201