Skip to content

Instantly share code, notes, and snippets.

@JoshuaCurry
Created May 29, 2018 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshuaCurry/cd3713a722a775a187e3cfe7cc0295d0 to your computer and use it in GitHub Desktop.
Save JoshuaCurry/cd3713a722a775a187e3cfe7cc0295d0 to your computer and use it in GitHub Desktop.
#!/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