-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Added newtons_second_law_of_motion.py #5441
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, acceleration): | ||
""" | ||
>>> newtons_second_law_of_motion(10, 10) | ||
100 | ||
>>> newtons_second_law_of_motion(2.0, 1) | ||
2.0 | ||
""" | ||
force = float() | ||
try: | ||
force = mass * acceleration | ||
except Exception as e: | ||
return e | ||
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") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
newtons_second_law_of_motion
. If the function does not return a value, please provide the type hint as:def function() -> None:
Please provide type hint for the parameter:
mass
Please provide type hint for the parameter:
acceleration