-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Added Coulomb_Law #8714
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
Merged
Merged
Added Coulomb_Law #8714
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
770e2f4
Create coulomb_law.py
gudlu1925 8466f25
Update coulomb_law.py
gudlu1925 07f24ca
Update coulomb_law.py
gudlu1925 112b1f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fdd4eff
Update and rename coulomb_law.py to coulombs_law.py
gudlu1925 43bd954
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2387620
Update coulombs_law.py
gudlu1925 d7d6517
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 64fceb5
Update coulombs_law.py
gudlu1925 c78a384
Update coulombs_law.py
gudlu1925 ce65ffb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1a32040
Update coulombs_law.py
gudlu1925 ed46580
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a8bd7cc
Update coulombs_law.py
tianyizheng02 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 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,37 @@ | ||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||
Coulombs law states that the magnitude of the electrostatic force of attraction or repulsion between two point charges | ||||||||||||||||||||||||||||||||||||||||||||
is directly proportional to the product of the magnitudes of charges and inversely proportional to the square of the distance between them. | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
Coulomb studied the repulsive force between bodies having electrical charges of the same sign. | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
F = k*q1*q2/r^2 | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
k is Coulomb's constant and equals 1/(4π*ε0). | ||||||||||||||||||||||||||||||||||||||||||||
q1 is charge of first body (C) | ||||||||||||||||||||||||||||||||||||||||||||
q2 is charge of second body (C) | ||||||||||||||||||||||||||||||||||||||||||||
r is distance between two charged bodies (m) | ||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
def coulombs_law(q1: float, q2: float, radius: float) -> float: | ||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
>>> round(coulombs_law(15.5,20,15),2) | ||||||||||||||||||||||||||||||||||||||||||||
12382849136.06 | ||||||||||||||||||||||||||||||||||||||||||||
>>> round(coulombs_law(1,15,5),2) | ||||||||||||||||||||||||||||||||||||||||||||
5392531075.38 | ||||||||||||||||||||||||||||||||||||||||||||
>>> round(coulombs_law(20,-50,15),2) | ||||||||||||||||||||||||||||||||||||||||||||
-39944674632.44 | ||||||||||||||||||||||||||||||||||||||||||||
>>> round(coulombs_law(-5,-8,10),2) | ||||||||||||||||||||||||||||||||||||||||||||
3595020716.92 | ||||||||||||||||||||||||||||||||||||||||||||
>>> round(coulombs_law(50,100,50),2) | ||||||||||||||||||||||||||||||||||||||||||||
17975103584.6 | ||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||
if radius <= 0: | ||||||||||||||||||||||||||||||||||||||||||||
raise ValueError("The radius is always a positive non zero integer") | ||||||||||||||||||||||||||||||||||||||||||||
return ((8.9875517923 * 10**9) * q1 * q2) / (radius**2) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||||||||||
import doctest | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
doctest.testmod(verbose=True) |
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.
Small grammar fix. Other than that, it looks good to go 👍