A4 · Midterm exam
Midterm exam: Python fundamentals
Five labs covering lessons 1 to 25. Give yourself two hours and work without the lessons open. Each lab is graded by hidden tests; read their messages if a check fails, fix, and check again. "Another set" deals a different exam.
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.
Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.