A4 Python for engineers · Practice
Problem set 6: program structure
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
For a series RLC with R = 10 Ω, L = 1 mH and C = 1 µF, set Z to a list of complex impedances at the frequencies in fs, and fmin to the frequency in fs where is smallest.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write a class Capacitor with attributes C (farads) and esr (ohms) and a method impedance(f) returning the complex . Set z = Capacitor(C * 1e-6, esr).impedance(f) and mag = abs(z).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An RC low-pass has with fc = 1000 Hz. Use bisection between fc and 1000 * fc to set f to the frequency where = g = 0.5, to within 1e-9 relative.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An R-2R DAC adds vref/2 for its first bit, vref/4 for the second, and so on. Write a recursive dac(bits, vref) for a list of 0s and 1s (most significant first), and set v = dac(code, vref) for the starter's code.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two resistors of 10 kΩ ±t% each form a 50% divider. With random.seed(1), draw 10,000 pairs (each resistor 10e3 * random.uniform(1 - t/100, 1 + t/100), top then bottom) and set frac to the fraction of dividers whose ratio is within ±spec% of 0.5.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using bisect.bisect_left on the sorted E24 list in the starter, set best to the E24 value nearest target = 3600.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set unique to how many distinct readings the list holds and repeats to how many readings are repeats of an earlier one, in one pass with a set.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two loggers recorded (time, value) pairs, each list sorted by time. Without calling sort or sorted, merge them in one pass into a single list sorted by time, taking logger A's entry first when times tie. Then set merged to that list, and q to the nearest-rank pth percentile (50) of all the values (you may sort the values for that).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in A4