A4 Python for engineers · Practice
Midterm exam
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
Write divider(Vs, R1, R2) returning a tuple (Vout, I, P): the output voltage, the current through the chain and the total power. Set Vout, I, P = divider(Vs, R1, R2).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write eng(x) formatting a positive number with an SI prefix and three significant figures (p, n, u, m, none, k, M), like eng(0.0047) → "4.7m". Set out to the list of eng applied to the starter's values.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Use Newton's update from until , and set x to the cube root of a = 3 and steps to the number of updates.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set by_node to a dictionary from each node to the sorted list of part names connected to it.
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 Res with value and tol (a fraction), a method bounds(), and a function series_bounds(parts) returning the lowest and highest total of a list of Res in series. Set lo, hi = series_bounds([Res(1000, t / 100), Res(2200, t / 100), Res(470, t / 100)]).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A rising signal is sampled once a millisecond: sample is . Using binary search over from 0 to 1000, set k to the first sample at or above f = 0.55.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter's slow_dupes is quadratic. Write fast_dupes(x) that returns the same sorted list of repeated values in one pass with sets, and set d = fast_dupes(x).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write parse_all(texts) returning the list of values in base units for strings like "4.7k", skipping (not crashing on) any string that can't be read. Set vals = parse_all(texts).
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