Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f66caa7

Browse files
committedOct 9, 2024·
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent fca65a2 commit f66caa7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed
 

‎electronics/electric_potential_point_charge.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44

55
COULOMB_CONSTANT = 8.99e9 # N·m²/C², Coulomb's constant
66

7+
78
def electric_potential_point_charge(charge: float, distance: float) -> float:
89
"""
910
Calculate the electric potential at a point due to a point charge.
10-
11+
1112
Parameters:
1213
- charge (float): The charge in Coulombs.
1314
- distance (float): The distance from the charge in meters.
14-
15+
1516
Returns:
1617
- float: The electric potential at the point.
17-
18+
1819
Raises:
1920
- ValueError: If both charge and distance are zero, or if distance is negative.
20-
21+
2122
Examples:
2223
>>> electric_potential_point_charge(1e-6, 0.05)
2324
179800.0
@@ -35,11 +36,13 @@ def electric_potential_point_charge(charge: float, distance: float) -> float:
3536
elif distance == 0 and charge == 0:
3637
raise ValueError("Charge and distance cannot both be zero.")
3738
elif distance == 0:
38-
return float('inf') # Potential is infinity when distance is zero
39+
return float("inf") # Potential is infinity when distance is zero
3940
elif charge == 0:
4041
return 0 # Zero potential for zero charge
41-
42+
4243
return (COULOMB_CONSTANT * charge) / distance
44+
45+
4346
if __name__ == "__main__":
4447
import doctest
4548

0 commit comments

Comments
 (0)
Please sign in to comment.