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)
| 16 | |
| 17 | |
| 18 | def 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 | |
| 39 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected