Skip to content

Commit 9849c88

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5d0f62f commit 9849c88

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

physics/ohms_law.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,55 @@ def ohms_law(current: float, resistance: float, decimals: int = 1) -> float:
44
55
Ohm's Law states that:
66
V = I * R
7-
7+
88
Where:
99
V = Voltage (Volts)
1010
I = Current (Amperes)
1111
R = Resistance (Ohms)
12-
12+
1313
Parameters:
1414
current (float): The current in Amperes (A).
1515
resistance (float): The resistance in Ohms (Ω).
1616
decimals (int): The number of decimal places to round the voltage. Default is 1.
17-
17+
1818
Returns:
1919
float: The calculated voltage in Volts (V).
20-
20+
2121
Examples:
2222
>>> ohms_law(2.0, 5.0)
2323
10.0
24-
24+
2525
>>> ohms_law(1.0, 4.0)
2626
4.0
27-
27+
2828
>>> ohms_law(3, 0.5)
2929
1.5
30-
30+
3131
>>> ohms_law(1.5, 2.0)
3232
3.0
33-
33+
3434
# Test case for invalid input (zero resistance)
3535
>>> ohms_law(2, 0)
3636
Traceback (most recent call last):
3737
...
3838
ValueError: Zero resistance
39-
39+
4040
# Test case for invalid input (zero current)
4141
>>> ohms_law(0, 3)
4242
Traceback (most recent call last):
4343
...
4444
ValueError: Zero current
4545
"""
4646
if current == 0:
47-
raise ValueError('Zero current')
47+
raise ValueError("Zero current")
4848
if resistance == 0:
49-
raise ValueError('Zero resistance')
49+
raise ValueError("Zero resistance")
5050

51-
voltage = current * resistance
51+
voltage = current * resistance
5252
return round(voltage, decimals)
5353

5454

5555
if __name__ == "__main__":
5656
import doctest
57+
5758
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)