Vote count:
0
I've made a code to calculate the resistance in a circuit. It considers each change between 'in series' and 'in parallel' to be a 'part', then is given the number of parts, number of resistors for each part, and resistance of each resistor.
def resistance():
p = int(input('Enter number of parts. One "part" is a resistor or sequence of resistors that are in parallel while the rest are in series, or vice versa.'))
for x in range(1, p):
n = input('Enter number of resistors in part' + x)
for y in range(1, n):
w = input('Enter the resistance of resistor #' + y)
q.append(w)
t = str(input('In series or parallel? Enter S for series, P for parallel.'))
if t == 'S':
for z in range(1, len(q)):
s += q[z-1]
elif t == 'P':
for v in range(1, len(q)):
s += (1/q[z-1])
q = []
return s
The problem is, whenever I run it, it takes in 'p', then gives the following error:
local variable 's' referenced before assignment
When I set s = 0 before the first loop, it just takes in 'p' then returns 0.
Can anyone tell me where this is going wrong?
asked 6 secs ago
Aucun commentaire:
Enregistrer un commentaire