zonelist = [] # list of overall resistance values for each zone
resilist = [] # values of resistors in a single path
patvlist = [] # each number is the sum of resistors in their path, with a zone
def inti(prompt):
while 1: # loop infinitely
x = raw_input('> ') # request a string
try:
new_x = int(x) # convert the input to a floater
break # the conversion was successfull: break out of the loop
except ValueError: # this block is accessed if the integer conversion fails
print 'Please enter an integer. Not a string.'
return new_x # return the floater
def pathos():
global zonevalue
counter1 = 0 # get totals for each path and then do appropriate calculations to get a total for the zone
for count in range(appnum): # For each path in the current zone
print 'How many resistors in path', counter1 + 1, '?'
resinum = inti('') # amount of resistors. used so that the values are asked for that amount of times
counter1 = counter1+1
counter2 = 0
for count in range(resinum): # plug in resistor values
print 'What is the value of resistor', counter2 + 1, '?'
appnumres = inti('')
resilist.append(appnumres) # put the number in a sequence
counter2 = counter2 + 1
seriesval = sum(resilist) # get the sum of the resistances on that path
invseriesval = (1/seriesval) # get reciprocal for parallel circuit
print invseriesval
if appnum > 1: # if the zone has parallel paths, use reciprocal
patvlist.append(invseriesval)
else: # if the zone is a series, ie it has one path, just use the sum
patvlist.append(seriesval)
sum_of_all_paths = sum(patvlist) # add up the sum of the paths
if appnum > 1: # if parallel, get the reciprocal
zonevalue = sum_of_all_paths**-1
else: # otherwise just return the series value (coulda done this tidier...)
zonevalue = seriesvalprint 'How many zones in the circuit?'
z = inti('') # number of zones in circuit. used to dictate number of loop that asks for amount of paths in each zone
counter = 0 # sets up counter
for x in range(z):
print 'How many paths in zone', counter + 1, '?'
appnum = inti('') # asks for amount of paths, so that the pathos loop can be run a sufficient amount of times
pathos()
zonelist.append(zonevalue)
counter = counter + 1
total_resistance = sum(zonelist)
print 'The total resistance in the circuit is', total_resistance, 'ohms.'