A4 · Problem set 2
Problem set 2: the basics
These labs use lessons 1 to 10: numbers, strings, conditionals, loops and functions. Each one is a small, complete engineering calculation. Read the hidden tests' messages when a check fails: they say which case went wrong.
Check
Write battery_life(capacity_mAh, current_mA, derate=0.8) returning the hours a battery lasts when only derate of its rated capacity is usable. Set h1 = battery_life(Q, I) and h2 = battery_life(Q, I, derate=1.0) for Q = 1000 mAh and I = 0.5 mA.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
TTL logic reads an input as low at or below 0.8 V, high at or above 2.0 V, and undefined in between. Write level(v) returning "low", "high" or "undefined", and set s = level(v) for v = 0.8 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Add up for , stopping before the first term smaller than tol = 1 × 10⁻⁸. Set total to the sum and n to how many terms you added.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A diode and a resistor R = 220 Ω are in series across Vs = 5 V. The diode's voltage is . Starting from , repeat until changes by less than A. Set I to the result and Vd to the diode's voltage then.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write ones(n) returning how many 1 bits a non-negative integer has, using % and // (no bin). Set c = ones(n) for n = 95.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write adc_volts(code, bits, vref) returning code * vref / 2**bits, or None if code is outside 0 to 2**bits - 1. Set v = adc_volts(int(f * 2**bits), bits, vref) and bad = adc_volts(2**bits, bits, vref).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write report(name, value, unit, lo, hi) returning a line like "TP3: 4.57 V ok": the name, a colon, the value to three significant figures, the unit, and ok if lo <= value <= hi, else FAIL. Set line = report(f"TP2", x, "V", lo, hi).
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
7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.