File tree 1 file changed +13
-5
lines changed
1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def charging_capacitor(
24
24
resistance : float , # resistance in ohms.
25
25
capacitance : float , # capacitance in farads.
26
26
time_sec : float , # time in seconds after charging initiation of capacitor.
27
- ) -> float :
27
+ ):
28
28
"""
29
29
find voltage of capacitor at any nth second after the initiation of it's charging.
30
30
@@ -83,21 +83,29 @@ def charging_capacitor(
83
83
raise ValueError ("source voltage cannot be negative." )
84
84
elif source_voltage == 0 :
85
85
raise ValueError ("source voltage cannot be zero." )
86
+ else :
87
+ return None
86
88
elif resistance <= 0 :
87
89
if resistance < 0 :
88
90
raise ValueError ("Resistance cannot be negative." )
89
91
elif resistance == 0 :
90
92
raise ValueError ("Resistance cannot be zero." )
93
+ else :
94
+ return None
91
95
elif capacitance <= 0 :
92
96
if capacitance < 0 :
93
97
raise ValueError ("Capacitance cannot be negative." )
94
98
elif capacitance == 0 :
95
99
raise ValueError ("Capacitance cannot be zero." )
100
+ else :
101
+ return None
96
102
else :
97
- return round (
98
- source_voltage * (1 - exp (- time_sec / (resistance * capacitance ))),
99
- 3 ,
100
- )
103
+ if resistance != 0 :
104
+ return round (
105
+ source_voltage * (1 - exp (- time_sec / (resistance * capacitance ))), 3
106
+ )
107
+ else :
108
+ return None
101
109
102
110
103
111
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments