MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / coulombs_law

Function coulombs_law

physics/coulombs_law.py:18–36  ·  view source on GitHub ↗

Calculate the electrostatic force of attraction or repulsion between two point charges >>> coulombs_law(15.5, 20, 15) 12382849136.06 >>> coulombs_law(1, 15, 5) 5392531075.38 >>> coulombs_law(20, -50, 15) -39944674632.44 >>> coulombs_law(-5, -8, 10) 359502071

(q1: float, q2: float, radius: float)

Source from the content-addressed store, hash-verified

16
17
18def coulombs_law(q1: float, q2: float, radius: float) -> float:
19 """
20 Calculate the electrostatic force of attraction or repulsion
21 between two point charges
22
23 >>> coulombs_law(15.5, 20, 15)
24 12382849136.06
25 >>> coulombs_law(1, 15, 5)
26 5392531075.38
27 >>> coulombs_law(20, -50, 15)
28 -39944674632.44
29 >>> coulombs_law(-5, -8, 10)
30 3595020716.92
31 >>> coulombs_law(50, 100, 50)
32 17975103584.6
33 """
34 if radius <= 0:
35 raise ValueError("The radius is always a positive number")
36 return round(((8.9875517923 * 10**9) * q1 * q2) / (radius**2), 2)
37
38
39if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected