title: Python 3 - Electronics Analysis Script
body: <p>I hope someone can point me in the right direction for a script I want to improve. I am studying electronics and have written some Python script to help with the calculations. I have written and small basic script which assists me in calculating the correct resistor value's for a transistor amplifier. </p>
  
  <p>The problem I have is when the required resistors are calculated, I have values that are not matching the standard resistor values.</p>
  
  <p>For Example:</p>
  
  <p>Standard Resistor Values: 100, 150, 275, 340, 420, 550</p>
  
  <p>The result of the calculation in the script gave me a resistor value of 176.</p>
  
  <p>How could I use Python to select the nearest standard value.</p>
  
  <p>If the calculation was 176 then another line of text would say 'Choose a 150 Resistor for the circuit'</p>
  
  <p>I know I can use lists so I can reference the values but I just need a small sample of how I put the script together to show the actual value then reference the standard values from the list.</p>
  
  <p>Hope this makes sense. Any help much appreciated.</p>
  
  <p>My script is very basic but it does the job. Improvements will come later.</p>
  
  <pre><code>Av = 15
  Rc = 3300
  Vs = 10
  Vc = 6
  beta = 100
  
  Re = Rc / Av
  Ic = (Vs - Vc) / Rc
  Ve = Re * Ic
  Vb = Ve + 0.7
  Ib = Ic / beta
  I2 = 10 * Ib
  R2 = Vb / I2
  R1 = (Vs - Vb) / (I2 + Ib)
  
  print ('Re =',Re)
  print ('Ve =',Ve)
  print ('Vb =',Vb)
  print ('Ic =',Ic)
  print ('Ib =',Ib)
  print ('I2 =',I2)
  print ('R2 =',R2)
  print ('R1 =',R1)
  </code></pre>
  
  <p>It calculates the voltage and current at each part on the transistor and shows the value required for R2 and R1 based on gain and voltage supplied etc.</p>