Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/python2.7
class Capacitor:
def __init__(self, name, price, post, volts, capacitance):
self.n = name
self.p = price
self.post = post
self.v = volts
self.c = capacitance
caps = []
with open("capvals.txt", "r") as f:
for line in f.readlines():
p = line.split(",")
caps.append(Capacitor(p[0], float(p[1]), float(p[2]), float(p[3]), float(p[4])))
vreq = float(raw_input("What voltage do you want? (V): "))
creq = float(raw_input("What capacitance do you need (nF): "))
for cap in caps:
nseries = float(vreq/cap.v)
nparallel = float((creq*nseries)/cap.c)
total = nseries*nparallel
totalprice = cap.p*total+cap.post
print cap.n + ": You need " + str(total) + " (" + str(nseries) + " series, " + str(nparallel) + "parallel) costing GBP " + str(totalprice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.