diff --git a/README.md b/README.md index eb43e3d5c2835d606cc4232ccb9603ea04011a1c..ef51be5845222346ffae1d42f0fb52c05dc89313 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ while True: # Task 5 -## Taking notes: +### Taking notes... ## Ohm's law: `V = I * R` to calculate Voltage @@ -186,7 +186,7 @@ R = Resistance `R = V / I` to calculate Resistance -### Additionally +### Additionally... >Ohm’s law states that the voltage (V) across a resistor is proportional to the current (I), where the constant of proportionality is the resistance (R). @@ -198,7 +198,7 @@ R = Resistance `R = R1 + R2 + ... + Rn` -## This can be implemented in Python using pint +## This can be implemented in Python using 'pint' library ``` import RPi.GPIO as GPIO @@ -214,7 +214,8 @@ voltage = (resistance * current).to('volt') ### Moreover, I have created an `ohms_law.py` and `tests.py` in the /ohms_law directory. Example (testing resistance function): -Expected output from 30V and 3A = 10Ω +Expected output from **30V and 3A = 10Ω** + ``` def test_resistance_calculation(): # Test when voltage is 24 V and current is 6 A @@ -237,7 +238,7 @@ if __name__ == '__main__': ``` ### Other functions have been implemented -*Final code (ohms_law.py)* +*Final code (ohms_law.py):* ``` import pint @@ -267,9 +268,14 @@ def calculate_resistance(voltage, current): resistance = voltage / current return resistance + +def calculate_serial_resistance(rs): + # Calculate the total resistance for resistors in series (r_total = R1 + R2 + ... = Rn) + r_total = sum(rs) + return r_total ``` -*Final code (tests.py)* +*Final code (tests.py):* ``` import pint diff --git a/ohms_law/ohms_law.py b/ohms_law/ohms_law.py index b19bcfed9c53055cee4b5a23a2cafd5088a11a58..3716db9819588c8fc7efbf3c5fc8a67b89bc303b 100644 --- a/ohms_law/ohms_law.py +++ b/ohms_law/ohms_law.py @@ -24,4 +24,9 @@ def calculate_resistance(voltage, current): current = current * ureg.ampere resistance = voltage / current - return resistance \ No newline at end of file + return resistance + +def calculate_serial_resistance(rs): + # Calculate the total resistance for resistors in series (r_total = R1 + R2 + ... = Rn) + r_total = sum(rs) + return r_total \ No newline at end of file