A4 Python for engineers · Practice
Every topic, mixed
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.
Topics: all 56
Check
Write a function power(V, R) that returns the power, in watts, that a resistor dissipates with voltage across it.
This lab's V = 10 V and R = 15 Ω are already defined, in volts and ohms.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write parallel(R1, R2) that returns the resistance of two resistors in parallel, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write divider(Vs, R1, R2) returning a divider's output voltage, then print it for this lab's values with three significant figures, like Vout = 3.84 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A wire's resistance is , with the area of its cross-section. Write wire_resistance(rho, L, d) with everything in SI units (meters). Then set R for copper ( Ω·m) of length L = 2 m and diameter d = 0.5 mm.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write current(V, R) returning the current through a resistor.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write tau(R, C), the time constant in seconds, and print it in milliseconds with three significant figures.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write db(r) that returns a power ratio in decibels.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write energy_wh(Q, V): a battery's energy in watt-hours from its capacity Q in mAh and its voltage V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Sample number n = 4230 goes into a circular buffer of length N = 16. Set slot to its position (0 to N − 1) and wraps to how many full times the buffer has filled before it.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write wrap(angle) that brings any angle in degrees into the range 0 to 360 (360 itself not included). Then set w to wrap(a) with a = 725.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The code adds dt = 0.2 to a running total n = 10 times. Set same to whether the total matches n * dt, using math.isclose so that rounding error doesn't count as a difference.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make a list times of every time from 0 to T = 2 s inclusive in steps of dt = 0.1 s, computing each from an integer counter so the last one is exactly T.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A 12-bit ADC turns a voltage from 0 to Vref = 2.5 V into a whole-number code from 0 to 4095, one step being Vref / 4096. Set lsb to one step in volts, v to the voltage for code c = 513 (c * lsb), and code to the code for x = 0.855 V: the nearest whole step, as an int, clipped to the range 0 to 4095.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A clock counts s = 33316 seconds since midnight. Set h, m and sec to the hours, minutes and seconds.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set r to v = 2.718 rounded to n = 1 decimal places.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set q to a // b and f to a / b, with a = 9 and b = 2, and set diff to f - q.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write fmt(x, unit) that returns a string with x to three significant figures, a space, then the unit, like fmt(4.567, "V") → "4.57 V". Then set s = fmt(x, "Hz") with x = 4.567.
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) that returns x scaled to a value from 1 to under 1000, with three significant figures and a prefix letter (p, n, u, m, none, k, M, G), like eng(4700) → "4.7k" and eng(0.0033) → "3.3m". Then set e = eng(v) with v = 0.0033.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write parse(text) that turns a value with an optional prefix letter into a number: parse("4.7k") → 4700, parse("100n") → 1e-07, parse("330") → 330. Then set x = parse(s) for the string s the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A parts list has lines like "R1, 4.7, 5%". The starter builds one for you. Set part (the name), value (a float) and tol (a fraction, so 5% is 0.05).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A bench meter answers a query with strings like "+4.71230E+00 VDC": a number in scientific notation, a space, then a unit. Write reading(text) returning (value, unit) with value a float. Then set r = reading(reply) for the reply the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set s to x = 12350 in scientific notation with two digits after the point, like "1.23e-04".
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set line to the three numbers a = 2, b = 10 and c = 7 joined with commas and no spaces, like "1,10,3".
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set has_prefix to whether the string s the starter picks ends in a letter.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write field(x, pos, width) returning the width-bit field of x that starts at bit pos. Then set f = field(reg, pos, width) with reg = 0xBEEF, pos = 0 and width = 4.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write set_field(x, pos, width, value) returning x with its width-bit field at pos replaced by value, leaving every other bit alone. Then set y = set_field(reg, pos, 4, v) with reg = 0xBEEF, pos = 0 and v = 9.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write tmp102(b1, b2) that turns a TMP102's two bytes (most significant first) into °C: the top 12 bits of the 16-bit value, two's complement, times 0.0625. Then set t for the byte pair the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
What is 0x66 in decimal?
Check
Write checksum(bs) returning the XOR of all the bytes in a list, and valid(packet) returning True when the last byte of packet equals the checksum of the bytes before it. Then set c = checksum(data) and ok = valid(packet) for the packet the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A 16-bit signed register reads 32767 when you treat it as unsigned. What signed value does it hold?
Check
Set ones to how many bits of x = 0x00FF are 1, using a loop with & 1 and >>.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set s to the byte b = 91 written as exactly 8 binary digits (with leading zeros) and h as exactly two capital hex digits, both as strings.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A meter answers a "read all" query with comma-separated readings in E notation. Write stats(reply) returning (mean, pk2pk), the mean and the largest minus the smallest reading. Then set s = stats(reply) for the reply the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write volts(b, vref=2.048) for a 24-bit bipolar converter: three bytes, most significant first, two's complement, volts per count. Then set v for the bytes the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A bench supply takes the commands VOLT <v> and CURR <i>, with the voltage to 3 decimals and the current to 4, then OUTP ON. Write setup(v, i) returning the three commands as one string separated by "\n". Then set cmd = setup(v, i) for v = 1.25 and i = 0.01.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A converter's control register takes the channel in bits 0 to 3, a gain code in bits 4 to 6, and a start flag in bit 15. Write control(ch, gain, start) returning the register value, and decode(reg) returning (ch, gain, start) back from it. Set reg = control(ch, gain, start) for ch = 5, gain = 0 and start = 1, and back = decode(reg).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write table(rows) that formats a list of (name, value, unit) rows as text, one row per line: the name left-aligned in 8 characters, the value right-aligned in 10 characters with 4 significant figures (.4g), a space, then the unit. Set text = table(rows) for the rows the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A bipolar 16-bit converter covers −1.25 V to +1.25 V. How many volts is one count?
Write units the way you normally would: 1.5 V, 1500 mV and 0.0015 kV are the same answer.
Check
Write eng(x, unit) returning a string like "4.7 kΩ": the value scaled to a number from 1 up to (not including) 1000 with the matching prefix (p, n, µ, m, none, k, M, G), shown with :g, a space, then the prefix and unit. Set s = eng(v, "Ω") for v = 3.3 × 10⁻⁷.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Add 0.1 to a running total n = 10000 times in a loop, starting from 0.0. Set total to the result, err to abs(total - n / 10), and exact to math.fsum of the same n values (which rounds only once).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write hms(seconds) returning a string "h:mm:ss" (hours with no padding, minutes and seconds with two digits) using // and %. Set s = hms(T) for T = 3600.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write sig(x, digits) rounding a positive number to digits significant figures with round and math.log10. Set y = sig(x, d) for x = 98765 and d = 2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A 16-bit status register packs fields: bits 0 to 3 are the channel, bits 4 to 7 the gain code, and bit 15 an error flag. Write fields(reg) returning (channel, gain, error) using >> and &, with error a bool. Set f = fields(reg) for reg = 1234, and h = f"{reg:04X}".
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write rating(P) that returns the smallest of 0.125, 0.25, 0.5, 1, 2 and 5 W that is at least twice P, or None if none is. Then set r = rating(V**2 / R) for V = 10 V across R = 15 Ω.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write status(measured, nominal, tol_pct) returning "low", "ok" or "high", where ok means within ±tol_pct percent of nominal (edges count as ok). Then set s = status(f * nom, nom, tol).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write diode_current(v, R): 0 for v up to 0.7 V, and above. Then set i = diode_current(v, R) for v = 0.3 V and R = 100 Ω.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write heater(on, T) with hysteresis: on below 19 °C, off above 21 °C, and unchanged in between. Starting with the heater off, set s1 = heater(False, T1) and then s2 = heater(s1, T2).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A meter has ranges of 0.2, 2, 20 and 200 V. Write pick_range(v) returning the smallest range whose full scale is at least the size of v (so −1.5 V needs the 2 V range), or the string "OL" if none is big enough. Then set rng = pick_range(v) for v = 0.05.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Without using max, set m to the largest of a = 8, b = 5 and c = 0.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write sign(x) returning −1, 0 or 1. Set s = sign(x) with x = 0.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set inside to whether V = 5 is between lo = 3 and hi = 13 inclusive, using a chained comparison.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A ladder has n = 15 resistors in series: the first is R0 = 100 Ω and each one after is d = 10 Ω bigger. Set total to their sum, using a for loop.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using a while loop, set n to the smallest whole number with M = 1000.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Find for a = 10 by repeating from until . Set x to the result and steps to how many updates it took.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor charges as after k steps of . Set k to the first step at which it exceeds f = 0.95.
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 driven by a 1 V step obeys when stepped forward by Euler's method, with . Starting from , run n = 50 steps with r = 0.1 in a for loop. Set v to the final value and err to how far it is from the exact .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set f to for n = 8, with a for loop.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set count to how many whole numbers from lo = 10 to hi = 100 inclusive are multiples of m = 7.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A battery keeps of its charge each month (r = 0.02). Set months to the first whole month when it's at or below target = 0.5 of full.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write divider(Vs, R1, R2=10e3) returning the output voltage, with R2 defaulting to 10 kΩ. Then set a = divider(Vs, R1) and b = divider(Vs, R1, R2=R1), with Vs = 5 and R1 = 1500.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write polar(x, y) returning the pair (r, theta) with theta in degrees from math.atan2. Then set r, theta = polar(x, y) for x = 5 and y = 4.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write average(f, a, b, n=1000) that averages f over n equally spaced midpoints of [a, b]. Then set m = average(lambda t: t**p, 0, 1) with p = 3.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write rc_corner(R, C, unit="Hz") returning the corner frequency in hertz, or when unit="rad/s". Set fc = rc_corner(R, C) and wc = rc_corner(R, C, unit="rad/s").
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write make_divider(R1, R2) that returns a function: given a source voltage, that function returns the divider's output . Then set div = make_divider(R1, R2) for R1 = 3900 Ω and R2 = 1500 Ω, and out = div(Vs) for Vs = 12 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write resistor(V, R) returning (I, P). Set I, P = resistor(V, R).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write twice(f, x) that returns f(f(x)). Set y = twice(lambda t: t * k, 1) with k = 3.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write led(Vs, Vf, I_max) returning (R, rating): the smallest E12 resistor (from the starter's values) that keeps the current at or below I_max amps, and the smallest of 0.125, 0.25, 0.5 and 1 W that's at least twice its dissipation. Then set R, rating = led(Vs, Vf, I / 1000) for Vs = 5 V, Vf = 1.8 V and I = 20 mA.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes temps, a day of room temperatures, one per minute. A thermostat turns the heater on when the temperature is below lo = 19 °C and off when it's above lo + band (1 °C higher), and otherwise leaves it as it was. Starting with the heater off, set on to a list of the heater's state each minute, switches to how many times it changed, and duty to the fraction of minutes it was on.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A current source of Ic = 10 µA charges C = 47 nF until the voltage reaches Vth = 3 V, when it's discharged to zero at once. Simulate 0.5 s in steps of 10 µs. Set n to the number of discharges, period to the average spacing between them in seconds, and ideal to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write bisect(f, a, b, tol=1e-9), which halves [a, b] until it's narrower than tol times b and returns its midpoint (assume f(a) and f(b) have opposite signs). Use it with a lambda to set f to the frequency, between 1 Hz and 100 MHz, where an RC low-pass with corner fc = 1000 Hz has gain g = 0.5: the gain is .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write sweep(start, stop, n=10, log=False) returning a list of n values from start to stop inclusive: evenly spaced, or with equal ratios between neighbors when log=True. Then set lin = sweep(a, b, n) and geo = sweep(a, b, n, log=True) for a = 10, b = 1000 and n = 11.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A 5 µA current source charges 100 nF from 0 V. How long until the capacitor reaches 3 V?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
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.
Check
Make a list readings of n = 7 values, where reading k is v0 + d * k (with v0 = 3.3, d = 0.02). Then set mean to their average and last3 to the last three readings.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The list x (made for you) holds noisy readings. Set above to a list of the readings greater than t = 5, and count to how many there are.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set s to the sample standard deviation of the list x (made for you), using the formula.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using the E12 list made for you, set best to the E12 value closest to target = 3600 Ω.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes x, a list of noisy readings. Set smooth to its w-point moving average (3 points): entry i is the mean of x[i] through x[i + w - 1], so smooth is w - 1 entries shorter than x. Use a loop and slices, without NumPy.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set evens to the list of even numbers from 0 to n = 9 inclusive, using a comprehension.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The list x = [5, 3, 9, 1, 7, 2, 8, 6]. Set part to the slice from index a = 2 up to (not including) b = 6, sorted.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set volts to a list of floats from the string "3.3,5,12,24", then set n_big to how many are greater than s = 5.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using the DIGIT dictionary in the starter, write decode(b1, b2, mult) for a three-band resistor. Then set value for the bands the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Count how many of each kind of part (the first letter of each name) the list holds. Set counts to a dictionary like {"R": 3, "C": 2}.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set nodes to the set of every node in the netlist, and n to how many there are.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Build parts as a dictionary mapping "R1" to R = 470 and "R2" to twice that. Then add "R3" equal to the two in series, and set total to the sum of all three values.
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 netlist is a list of (part, node_a, node_b) tuples. Set on_node to a dictionary mapping each node name to the sorted list of parts that touch it.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set common to the set of nodes that appear in both lists.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make the tuple pt = (x, y) and then unpack it into px, py. Set d to the distance from the origin.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write peaks(x, threshold) returning the indices of the local maxima of a list: entries greater than both neighbors and above threshold (the first and last entries never count). Set p = peaks(x, th) for the starter's list and th = 2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two boards' parts lists are dictionaries from part number to quantity. Write merge(a, b, boards_b=1) returning one dictionary with the total of each part, where b is needed boards_b times. Set m = merge(main, sensor, k) for 3 sensor boards.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write stats(x) that makes a single pass over a list and returns (lo, hi, rms), its minimum, maximum and RMS, without min, max or sum. Set s = stats(v) for the starter's n = 1000 readings.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A test plan lists test points, and the bench log records which were measured (some more than once, and some by mistake that aren't in the plan). Using sets, set missed to the sorted list of planned points never measured, extra to the sorted list of measured points not in the plan, and coverage to the fraction of the plan measured, after logging m = 5 more points from the starter's more list.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An ADC's noisy readings sit around one value. Using a dictionary, count how often each code appears, then set mode to the most common code (the smallest one if there's a tie), spread to the largest code minus the smallest, and counts to the dictionary. The starter makes n = 1000 codes.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A small sensor array's readings are a list of rows. Write transpose(m) returning its columns as rows, without NumPy, then set t = transpose(grid), col_sums to the sum of each column, and row_r to row 1 of the transpose.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Each part is a tuple (name, ohms, tolerance_percent). Set ranked to the list of names sorted by tolerance, tightest first, and by value within the same tolerance, then top to the first k = 2 names.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For the sweep the starter picks, set fpk to the frequency where the gain g is largest.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set best to the value in values (from the starter) nearest target = 3600, using min with a key.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set ups to the list of indexes k where the samples cross zero going up, between sample k and k + 1 (sample k below 0, sample k + 1 at or above 0).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set ok to whether every reading is below lim = 5.3 V, and any_low to whether any reading is below 4.75 V, using all and any.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using one list comprehension with enumerate, set bad to the list of (index, value) pairs for the readings outside lo = 4.75 to hi = 5.1 V (the edges count as in range). Then set n_bad to how many there are.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make bom a dictionary from the two lists names and vals with dict(zip(...)).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set by_value to the parts sorted from smallest value to largest.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set diffs to the list of differences between neighboring samples, x[k+1] - x[k].
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write current(V, R) that returns V / R, but raises a ValueError if R is zero or negative. Then set I = current(V, R) for V = 5 and R = 100.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write safe_float(text) that returns float(text), or None if the text isn't a number. Then set vals to safe_float applied to each string in the starter's list.
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 mean_abs has a bug. Fix it so it returns the mean of the absolute values, then set m = mean_abs(xs).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Look up each name in the parts dictionary. Set values to the list of their values, using 0 for any name that isn't in it, without letting a KeyError stop the program.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write to_int(text) returning int(text), or −1 if that fails. Set n = to_int(s) for the starter's string.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write rc_tau(R, C) returning R * C, raising ValueError if either is negative. Set t = rc_tau(1000, tau / 1000).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using the starter's bill of materials, write cost(boards) returning the parts cost in dollars for a run, where each part's lower price applies once its total quantity reaches 100. Then set total = cost(boards) for boards = 25 and each to the cost per board.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write loose_ends(net) returning the sorted list of nodes that appear only once in a netlist of (part, node_a, node_b) tuples, and shorted(net) returning the sorted list of parts whose two ends are on the same node. Set ends and shorts for the netlist the starter picks.
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 log has lines like R7=4712.3, but some are damaged. Write read_log(lines) returning (values, bad): a dictionary from name to float for the good lines, and a list of the line numbers (counting from 1) that couldn't be read, whether the = is missing or the value isn't a number. Set values, bad = read_log(lines).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write nearest_e12(x) returning the E12 value nearest to any positive x in ratio (smallest ), searching the decade below, the decade of x and the decade above. Set r = [nearest_e12(x) for x in xs] for the starter's list.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter has nominal and measured dictionaries for the same parts. Set report to a list of (name, error_pct) for the parts whose error, , is bigger in size than tol = 1%, sorted from the largest size of error to the smallest.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Each string in the starter's list is like "R1=4.7k". Using the parse function given, set bom to a dictionary from each name to its value in base units.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set m and s to the mean and sample standard deviation of x, then outliers to the readings more than 2 standard deviations from the mean, in their original order.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Count how many parts connect to each node. Set degree to a dictionary from node name to that count.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For the sweep in the starter, set gain_db to the list of gains in dB (), and f3 to the first frequency whose gain is more than 3 dB below the first one's.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Each part is a tuple (name, ohms). Set ranked to the list of names sorted by the power each dissipates at V = 5 V, largest first.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set avg to the moving average of x over a window of w = 4: entry i is the mean of x[i:i+w], for every full window.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Some strings in the starter's list aren't numbers. Set total to the sum of the ones that are, and bad to how many weren't, using try and except ValueError.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using math.log10, write db(power_ratio) returning of a power ratio. Set g = db(ratio) for ratio = 10.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
With cmath, set Z to the impedance of R = 1000 Ω in series with C = 10 nF at f = 10000 Hz, then mag = abs(Z) and deg to its angle in degrees.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Seed the generator with random.seed(s) (s = 7) and set draws to a list of n = 5 values from random.uniform(0.95, 1.05), then m to their mean using statistics.mean.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set med, sd and rng to the median, sample standard deviation and range (max minus min) of the starter's readings, using statistics.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using itertools.combinations on the E12 values from 1 kΩ to 8.2 kΩ in the starter, set pair to the two different values whose series sum is closest to target = 5500 Ω (as a sorted tuple), and err to how far that sum is from the target.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set r = cmath.sqrt(a) for a = −9, and im to its imaginary part.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set d = math.hypot(x, y) and ang to math.degrees(math.atan2(y, x)).
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 Resistor whose __init__(self, value, tol=0.05) stores value and tol, and whose bounds() returns (low, high). Set r = Resistor(R, t / 100) and lo, hi = r.bounds().
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Add a power(self, V) method returning . For the starter's list of resistors, set hottest to the one that dissipates the most at V = 12 V, and P to that power.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Give Resistor a __repr__ so that print(Resistor(4700, 0.01)) shows Resistor(4700, 1%). Set s = repr(Resistor(R, t / 100)).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using the Resistor class with bounds(), write divider_range(Vs, top, bottom) returning the lowest and highest possible output. Set lo, hi = divider_range(Vs, Resistor(10e3, t / 100), Resistor(10e3, t / 100)).
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 RC whose __init__(self, R, C) stores the two values, with methods tau() returning , corner() returning in hertz, and gain(f) returning . Then set lp = RC(R, C) for R = 4700 Ω and C = 2.2 × 10⁻⁹ F, and g = lp.gain(f) at f = 1000 Hz.
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 RC with attributes R and C and a method tau() returning R * C. Set t = RC(v * 1000, c).tau().
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make a list of n = 3 Part objects with values 100, 200, ..., and set total to the sum of their value attributes.
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 Debouncer(n) whose step(x) takes a 0 or 1 sample, changes the debounced state only after n = 3 samples in a row that differ from it, and returns True exactly when the state changes from 0 to 1. Then set presses to the number of presses it finds in the starter's samples raw.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write frames(stream) for the framing in the second example (0x7E, a length, the data, then the XOR checksum of the data), returning a list of (data_bytes, ok) pairs. Set got = frames(stream) for the stream the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A vending machine takes coins of 5, 10 and 25 cents. Its state is the credit so far. When the credit reaches price = 50 cents it dispenses, returns the change, and goes back to zero credit. Write vend(coins, price) returning (items, change): how many items it dispensed, and the list of change amounts it returned, for the coins the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write count_matches(bits, pattern) that counts every place a pattern of bits occurs in a stream, overlaps included (so 1, 0, 1, 0, 1 holds the pattern 1, 0, 1 twice), by stepping a state machine one bit at a time: the state is how many bits of the pattern currently match. Set n = count_matches(bits, pattern) for the starter's stream and pattern.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A traffic light holds green for g = 5 s, yellow for y = 2 s and red for r = 6 s, starting green. Using a table of durations and successors, set colors to the list of its color ("GREEN", "YELLOW" or "RED") at each whole second from 0 to 59, and red_frac to the fraction of those seconds that are red.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A toggle switch flips a lamp each time it's pressed. Starting with the lamp off, set lamp to its state (True for on) after n = 5 presses, using a loop that steps the state.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The table NEXT maps (state, letter) to the next state of a machine that accepts the word "ON". Starting in "S0", step it through the string s the starter picks and set accepted to whether it ends in "DONE". Inputs not in the table send it back to "S0".
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 Resistor with attributes ohms, tol (percent) and rating (watts), and methods limits() returning (lowest, highest) values, power(v) returning the power at voltage v using the nominal value, and safe(v) returning True if the power is at most half the rating, at the lowest value (the worst case). Set r = Resistor(R, t, P) for 1000 Ω, 1%, 0.5 W, and ok = r.safe(V) at 12 V.
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 Battery(capacity_mAh) that starts full. draw(mA, hours) uses up that much charge (never below zero), percent() returns the charge left as a percentage of capacity, and hours_left(mA) how long it could still supply mA. Set b = Battery(C), call b.draw(I, h), and set left = b.percent() and more = b.hours_left(I) for 1000 mAh, 50 mA and 6 hours.
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 Phasor(mag, deg) that stores a complex value, with __add__ and __mul__ returning new Phasors, and properties mag and deg (the angle in degrees). Set s = Phasor(a, p) + Phasor(b, q) and m = Phasor(a, p) * Phasor(b, q) for 3∠30° and 4∠60°.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using the fractions module, write parallel(*rs) returning the exact parallel combination of any number of resistances. Set R = parallel(Fraction(a), Fraction(b), Fraction(c)) for 6, 4 and 30 Ω, and top and bottom to its numerator and denominator in lowest terms.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write a base class Filter whose gain(f) returns the magnitude of its complex H(f), with subclasses LowPass(fc) and HighPass(fc) that define H(f) for first-order RC filters. Then write cascade(filters, f) returning the product of their gains. Set g = cascade([HighPass(f1), LowPass(f2)], f) for a band-pass from 100 Hz to 5000 Hz, at 2000 Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write a base class Sensor with read() returning self.convert(self.raw), and a subclass Thermistor(R0, B) whose convert(R) turns a resistance in ohms into °C by , with = 298.15 K. Set th = Thermistor(10000, 3950), set th.raw to the resistance it shows at 25 °C (from the inverse formula, R = R0 * exp(B * (1/T - 1/T0)) with T in kelvin), and t = th.read().
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using dataclasses, write a Measurement dataclass with fields name, value and unit, and a method line() returning "name: value unit" with the value to three significant figures (:.3g). Set ms to the starter's readings as Measurements sorted by value, largest first, and text to the line() of the first k = 2, joined by newlines.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A digital line is sampled at a steady rate. A real pulse is a run of at least m = 5 high samples between lows; shorter high runs are noise. Write a class PulseCounter(m) whose step(x) takes one sample and returns True at the low sample that ends a real pulse. Set count to the number of real pulses in the starter's samples, and widths to the list of their lengths in samples.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write the recursive ladder(n, R): R for n = 0, otherwise R in series with (R in parallel with ladder(n - 1, R)). Set Req = ladder(n, R) for n = 3 and R = 100.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write bisect(f, a, b, tol=1e-12) and use it to set r to the root of between 0 and c (c = 3).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write first_at_least(xs, target) by binary search, returning the index of the first value at or above target in a sorted list (or len(xs) if none). Use it on the starter's E12 list, and set v to the value found (or None if there isn't one).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write a recursive parallel_all(rs) returning the resistance of a list of resistors all in parallel: one resistor is itself, and otherwise it's the first resistor in parallel with parallel_all of the rest. Then set Req = parallel_all(rs) for the list the starter picks.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A thermistor has with = 10 kΩ at = 298.15 K and = 3950 K. Using bisection between 250 K and 400 K, set T to the temperature (in kelvins, within K) where it reads Rm = 5000 Ω, and steps to how many halvings that took.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Bisection starts on an interval 4 wide and stops once the interval is narrower than . How many halvings does that take?
Check
Write a recursive power2(n) returning (with power2(0) = 1). Set p = power2(n).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Use bisection on to set r to (a = 5), to within .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write count_pairs(n) that loops over all pairs i < j of n items and counts them. Set c = count_pairs(n) and formula = n * (n - 1) // 2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Rewrite the running total so it carries the sum forward in one pass. Set running to the list of cumulative sums of x.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set linear to the number of comparisons a linear search needs in the worst case on N = 1000000 items, and binary to the worst case for binary search, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set dupes to the sorted list of values that appear more than once in x, using a set so the work is linear.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write has_pair(xs, target) that returns True if two different entries of xs add up to target, in one pass with a set of the values seen so far (no nested loops). Then set found for the starter's readings and target = 7.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sort takes time proportional to . It takes 2.0 s on items. How long should it take on items?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A quadratic algorithm takes 1 s at n = 1000. Set t to the seconds it takes at m = 2 times that size.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set ratio to how many times fewer multiplications an FFT () needs than a naive DFT () for N = 65536.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write insertion_sort(a) returning a new sorted list and the number of comparisons it made, as (result, comparisons), counting each a[i] > key test. Set s, c = insertion_sort(x) for the starter's random list of n = 8 values, and c_rev to the comparisons for the list list(range(n, 0, -1)).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write merge(a, b) that merges two sorted lists into one sorted list in a single pass, taking from a when the front items tie, without calling sort or sorted. Set m = merge(a, b) for the starter's lists.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using your merge, write the recursive merge_sort(x) and count the comparisons it makes in total. Set s, c = merge_sort(x) for the starter's random list of n = 10 values, and bound to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Each part in the starter is (package, ohms, tolerance_pct). Set ordered to the list sorted by package alphabetically, then by tolerance from tightest to loosest, then by resistance from largest to smallest, using one call to sorted with a tuple key.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write percentile(x, p) returning the nearest-rank pth percentile of a list: sort it and take item number , counting from 1. Set q = percentile(delays, p) for the starter's 200 delays and p = 50.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Insertion sort is given a list of 50 distinct items in reverse order. How many comparisons does it make?
Check
Set by_len to the starter's words sorted by length, shortest first, with words of equal length kept in their original order.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Use bisect.insort to add v = 47 to the sorted list xs so it stays sorted, then set pos to the index where it landed using bisect.bisect_left.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
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.
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.
Check
Make t, 2001 evenly spaced times from 0 to 0.05 s, and v, the voltage at each of them. Then set vmax to the largest value in v.
A = 4 and f = 50 are already defined.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The samples in v cover exactly 4 cycles of a sine of amplitude 8. Compute their RMS value as rms.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The array E12 holds the E12 values in one decade. Set nearest to the E12 resistor, in ohms, nearest to target = 5300 Ω. (Look in the decade that contains the target.)
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter samples V every 0.1 µs for one period. Use np.diff to set slope to the rate of change between successive samples (in volts per second), and slew to its largest size. Then set rel to how far slew is from the exact peak rate , as a fraction.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For 4000 samples of over exactly 4 cycles, set frac to the fraction of samples above 0.7 × 4.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set s to the sum of the squares of the whole numbers from 1 to 21, using np.arange.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
I holds 500 current samples. Set P_avg to the average power they deliver to a 52 Ω resistor.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For the sine vin in the starter, set vout to the output of an amplifier with gain g = 3 that clips at ±L = 12 V, and frac to the fraction of samples that are clipped (where ), with no loops.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set vout to a half-wave rectifier's output with a diode drop of Vd = 0.6 V: the input minus Vd where that's positive, otherwise 0. Then set avg to its mean.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using broadcasting, set H to a table of RC low-pass gains with one row per corner in fcs and one column per frequency in f. Then set col to the column for 1 kHz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For the sampled signal in the starter, set ups to the array of indexes i where it crosses zero going up (sample i below 0, sample i + 1 at or above 0), with no loops, and peak_at to the index of its largest sample.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter samples a PWM signal (0 or 3.3 V) at 1 MHz for 20 periods. Using masks and no loops, set duty to the fraction of samples that are high, rises to the indexes i where sample i is low and sample i + 1 is high, and period to the average spacing between rises, in seconds.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set n_in to how many samples of x (made in the starter) lie between lo = 1 and hi = 3 inclusive, using a combined mask.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A constant current I = 0.5 A is sampled every dt = 0.001 s for 100 samples. Set q to the running charge np.cumsum(i) * dt, and q_end to its last value.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes X, 200 samples of 5 channels. Set means to each channel's mean, rms to each channel's RMS (), and loudest to the index of the channel with the largest RMS.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For every pair of E6 resistor (100 Ω to 680 kΩ) and capacitor (1 nF to 6.8 µF) in the starter, compute the corner frequency as a 2D array fc (rows for capacitors, columns for resistors). Set R_best, C_best to the pair whose corner is nearest target = 2000 Hz in ratio (smallest ).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set M to the n × n array (4 × 4) whose entry at row i, column j is , using broadcasting (no loops). Then set diag to its diagonal and col_sums to the sum of each column.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes T, an n × n grid of temperatures (5 × 5). Using slices and no loops, set inner to the grid without its outer border, and avg4 to the average of each inner point's four neighbors (up, down, left and right), an array the same shape as inner.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An ADC sends m = 3 channels interleaved: channel 0's sample, then channel 1's, and so on, then channel 0 again. The starter's data holds 200 rounds of them. Set X to the samples as one row per round and one column per channel, and p2p to each channel's peak-to-peak value (its maximum minus its minimum).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set A to np.arange(r * c) reshaped into r = 3 rows and c = 3 columns, and last_col to its last column.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set row_max to the largest value in each row of X, and where to the column where each row's maximum is.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter has an array R of resistor values in ohms. Each sits alone across V = 5 V. Set P to the array of their powers, total to the total power, and worst to the index of the resistor that dissipates the most, without loops.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes noisy samples v. Using a Boolean mask, set frac to the fraction of samples above th = 1 V, mean_above to the average of just those samples, and n_neg to how many are negative.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor discharges into a 10 Ω resistor from 10 V with time constant tau = 2 ms. The starter samples the power every 10 µs for 10 time constants. Set E to the energy delivered, by the trapezoid rule written with array slices (no np.trapz), and exact to with .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A thermal camera's image of a board is the 2-D array T in °C (made in the starter). Set hot to the (row, col) of the hottest pixel using np.argmax and np.unravel_index, row_means to the mean of each row, and over to how many pixels in row r = 2 exceed 60 °C.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using broadcasting, build ratio, a table of with down the rows and across the columns, both from the starter's E12 list (1 kΩ to 8.2 kΩ). Set n_good to how many pairs land within 1% of the target k = 0.4, and best to the (R1, R2) pair closest to it.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sine of amplitude A = 6 V goes through a clipper that limits it to ±L = 2.5 V. Using np.where (or np.clip), set out to the clipped samples, n_clipped to how many samples were changed, and rms_out to the RMS of the output.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A logic signal is sampled every microsecond. Threshold it at th = 1.65 V into 0s and 1s, then use np.diff to set rises to the sample indices where it goes from 0 to 1 (the index of the first 1), and width to the average number of samples each high pulse lasts.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot a capacitor's discharge, with = 1 ms, from 0 to , with time in milliseconds on the x axis. Label both axes and mark with a dashed vertical line.
V0 = 6 (volts) and tau = 1 (milliseconds) are already defined.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
On one set of axes, plot and over 40 ms, with time in ms, and add a legend naming them v1 and v2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter has ten measured points, voltages V and currents I in amps, from a resistor of about 2200 Ω. Plot the points as dots with no line joining them ('o'), then the straight line through them as a solid line over the same voltages. Label both axes with units.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot the output of a bits-bit ADC (3 bits, so codes 0 to 2**bits - 1, full scale 1 V) for an input ramp vin from 0 to 1 V over 1 ms, as a staircase: use plt.step(t_ms, code, where='post'), where code is np.floor(vin * 2**bits) clipped to the top code. Label both axes.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot the charging curve , = 1 ms, from 0 to ms, and draw a dashed horizontal line at 4 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make a Bode magnitude plot in dB of from 10 Hz to 1 MHz, with a log frequency axis. Store the dB values in mag_db.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot an RC low-pass's gain in dB, , against f on a log frequency axis, with fc = 1000 Hz. Label the axes with units.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make a figure with two stacked subplots sharing the frequency axis: gain in dB on top and phase in degrees below, both with log frequency axes, for the RC low-pass with fc = 500 Hz. Label each axis.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
On log-log axes, plot the impedance sizes of a C = 10 nF capacitor and an L = 1 mH inductor from 10 Hz to 10 MHz, with a legend naming them "C" and "L". Set fx to the frequency where they're equal.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
On one figure, plot a voltage V on the left y axis and the current through R = 22 Ω on a second y axis made with ax.twinx(), both against time in ms over 40 ms. Label each y axis with its unit.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes 2000 noisy readings of a 5 V reference (noise 2 mV standard deviation). Plot their histogram with plt.hist(x_mV, bins=40), where x_mV is each reading's error from 5 V in millivolts, and label the x axis with its unit and the y axis as a count.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot for t from 0 to 10τ (tau = 2 ms) on a log axis with plt.semilogy.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Plot the readings in the starter and draw a dashed horizontal line at the limit lim = 2.5 V with plt.axhline.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter captures v = −1.2 + 1·sin(2π·440·t) at 100 kHz for 5000 samples. Using the lesson's recipe, set vpp, freq (from interpolated upward crossings of v - v.mean()), and mean and rms (AC RMS) over the whole cycles between the first and last upward crossings.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A source of V = 5 V with internal resistance Rs drives a load RL. With Rs from the starter as a column and RL = np.logspace(0, 4, 401) as a row, compute the load power on the whole grid with broadcasting (no loops). Set P (shape (4, 401)), best to each row's best load and Pmax to each row's largest power.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
On one figure, plot the gain in dB of a second-order low-pass, , with f0 = 200 Hz, for = 0.5, 0.707 and 2, over f = np.logspace(np.log10(f0) - 2, np.log10(f0) + 2, 400). Use a log frequency axis, label both axes with units, and give each curve a legend label containing its Q, such as "Q = 0.707".
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes 10 000 readings with noise of standard deviation s = 0.5 mV around 1.000 V. Set counts, edges = np.histogram(err_mV, bins=50) for the errors in millivolts, within1 to the fraction of errors within one sample standard deviation of zero, and within3 to the fraction within three.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An amplifier with gain g = 3 clips at ±L = 5 V. For an input of 3 V amplitude at 50 Hz over 40 ms (2000 samples), plot the output against time in ms as a line, then mark only the clipped samples with red dots ('r.'), using a mask. Label both axes. Set frac to the fraction of samples clipped.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sine of amplitude 5 V is sampled finely over whole cycles. What fraction of the samples exceed V in size?
Check
For 10 cycles of sampled at 100 points per cycle (A = 1, f = 50 Hz, dc = 0.5 V), set vpp to the peak-to-peak value, vrms to the RMS of v, and vac to the RMS of v with its mean removed.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes noisy readings v sampled every millisecond. Set n_high to how many exceed th = 2.5 V, first_high to the time in ms of the first one (or None), and longest to the longest run of consecutive high samples.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For every pair of E12 resistors from 1 kΩ to 8.2 kΩ in the starter (top R1, bottom R2), compute the loaded divider output into a load RL = 1000 Ω as a 2D array vout (rows for R2, columns for R1). Set n_ok to how many pairs give an output within 1% of Vs / 3.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A second-order low-pass has . Make a two-subplot Bode plot (gain in dB on top, phase in degrees below, log frequency axes) from to , with f0 = 1000 Hz and Q = 0.7. Set peak_db to the largest gain in dB on your frequency grid.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
X holds 24 hourly readings for each of 7 days (shape 7 × 24, made in the starter). Set daily_mean (one per day), hourly_mean (one per hour, averaged over the days), and worst_day, worst_hour where the single largest reading is.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Full-wave rectify a mains sine of amplitude A = 170 V at f = 50 Hz (take ), sampled at 200 points per cycle over 5 cycles. Set vdc to the average of the rectified wave and ratio to vdc / A.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make a n × n grid of points with x and y from −1 to 1 using np.meshgrid, and set inside to the fraction of grid points with .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write zc(C, f) that returns a capacitor's complex impedance, .
C = 100 nF (in farads) and f = 50 Hz are already defined.
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 filter has . Compute mag, the size of at 10000 Hz, and phase_deg, its angle in degrees.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Add the phasors and in code. Set amp to the sum's amplitude and ang to its angle in degrees.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A series RLC has R = 10 Ω, L = 1 mH and C = 100 nF. Using a NumPy array of 200,001 frequencies from 1 kHz to 100 kHz, compute the complex impedance . Set f_min to the frequency where is smallest and Z_min to that smallest . Then set f0 to for comparison.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set Zmag to the size of the impedance of 52 Ω in series with 1.5 mH at 10000 Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set Zp to the complex impedance of 520 Ω in parallel with 15 nF at 1000 Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
With amplitude phasors and , set P to the average power, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Use np.roots to find all three roots of , and set r to them sorted from smallest to largest real part.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Solve this system with np.linalg.solve and set sol to the array of :
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor charges as with Vs = 9 V and tau = 10 ms. Write newton(f, df, x0), which repeats until a step is smaller than and returns . Use it from x0 = tau to set t to the time in ms when reaches Vt = 2 V, and iters to how many steps it took.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Solve , with np.linalg.solve; set x and y.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor charges as with = 1 ms. Use bisection (write it, or reuse yours) to set t_hit to the time, in ms, when it reaches 0.7 × 8 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Use np.roots to find the roots of ; set r to the root with the larger real part.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write stamp_R(G, a, b, R) that adds a resistor between nodes a and b to the conductance matrix G in place, with node 0 as ground (no row) and node in row . Then set G for the starter's random netlist of resistors on 4 nodes.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A current source pushes I = 2 mA into node 1. R1 = 1200 Ω goes from node 1 to ground, R2 = 4700 Ω from node 1 to node 2, and R3 = 8200 Ω from node 2 to ground. Build and with stamps and set v to the solved node voltages.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Build the bridge from the third example with modified nodal analysis: V = 9 V at node 1, 1 kΩ from 1 to 2, from 2 to ground and from 1 to 3, d = 0.9 kΩ from 3 to ground, and a meter of Rg = 10 Ω from 2 to 3. Set x to the solution vector (three voltages, then the source current) and Im to the meter current from node 2 to node 3.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A source Vs = 5 V feeds a divider, R1 = 1000 Ω on top and R2 = 4700 Ω below, and a load RL hangs across R2. Write load_power(RL) that builds and solves the circuit with modified nodal analysis and returns the power in RL. Then search RL over np.logspace(1, 6, 2001) and set RL_best to the value that maximizes the power, and Rth to the divider's Thevenin resistance, R1 in parallel with R2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For the starter's random resistor network on 3 nodes with a 1 mA source into node 1, solve for v, then check Kirchhoff's current law yourself: set kcl to an array holding, for each node, the total current leaving it through the resistors minus the current injected there. It should be zero to rounding error.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Node 1 connects to ground through 2.2 kΩ, to node 2 through 1.2 kΩ and to node 3 through 4.7 kΩ. What is the diagonal entry of the conductance matrix?
Write units the way you normally would: 1.5 S, 1500 mS and 0.0015 kS are the same answer.
Check
Set G to the 1 × 1 conductance matrix (a NumPy array) for two R = 2200 Ω resistors from node 1 to ground, using the stamp rule.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A current source pushes I = 3 mA into node 2 and out of node 1. Set i to the right-hand side vector for a 2-node circuit, in amps.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set fwd and ctr to the forward and central difference estimates of the derivative of at x0 = 1 with step h = 0.1, and e_fwd, e_ctr to their absolute errors against .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For , compute the central difference error for at x0 = 1. Set errs to the list of 13 errors and best_h to the with the smallest one.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate (I0 = 1 A, tau = 2 ms) from 0 to with the trapezoid rule on n = 40 steps. Set Q to the charge in coulombs and err to its relative error against the exact .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write simpson(y, h) for an odd number of samples (an even number of slices), and set S to the integral of from 0 to on n = 8 slices, and err to its error against the exact 2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter samples one period of a waveform v at n + 1 = 20 + 1 equally spaced points (the first and last are the same point in the cycle). Using the trapezoid rule written with NumPy slices (not a library integrator), set rms to . Then set exact to the known value: for a sine, for a square wave and for a triangle.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A central difference with step has an error of 4 × 10⁻⁶. Its error goes as while rounding is negligible. What should the error be with the step 10 times smaller?
Check
Sample (A = 1, f = 50 Hz) at 1000 points over one period, and set dv to np.gradient(v, t), its derivative. Set peak to the largest value of dv.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate from 0 to 1 with the trapezoid rule on n = 20 steps; set T to the result.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For a series RLC with = 50 Ω, L = 10 mH and C = 0.1 µF, set f to 20,001 frequencies spaced evenly in from 10 Hz to 1 MHz (np.logspace), Z to the complex impedances there, f_min to the frequency where is smallest, and f0 to .
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 ( = 1 kΩ, = 10 nF) shifts the phase by . Write bisect(g, a, b) (60 halvings), use it to set f to the frequency where the phase is , and set f_formula to the exact answer from .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sine with f = 200 Hz is sampled with step h. Write central(v, h) returning the central-difference derivative at the interior samples, (v[2:] - v[:-2]) / (2*h). Set err1 and err2 to the largest error against the exact derivative with 100 and 200 samples per cycle, and ratio = err1 / err2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A half-wave rectified sine is . Over one cycle, sampled at 10,001 points from 0 to , set rms_num to its RMS by the trapezoid rule (written with slices), rms_exact to , and avg to its average value by the same rule.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A series RLC circuit with = 100 Ω, = 10 mH and = 1 µF has the characteristic polynomial . Set roots to its roots with np.roots, kind to "under", "critical" or "over" (underdamped if the roots are complex), and zeta to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor C = 10 µF charges from 0 toward V = 5 V through R = 100 Ω. Sample 10 time constants at 20,001 points. With and , set E_source to , E_cap to and E_res to , each by the trapezoid rule, then half = E_cap / E_source.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate from 0 to (exactly 2) with n = 8 intervals. Write trapezoid(f, a, b, n) and simpson(f, a, b, n) (n even), and set e_t and e_s to their errors, abs(result - 2).
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 ladder DAC has nodes 1 to n (4 bits). Node 1 has a 2R resistor to ground; each node also has a 2R resistor driven by bit of the code (Vref = 5 V if the bit is 1, 0 V if it's 0); and an R resistor joins each node to the next. Using a stamped conductance matrix with each bit source as a Norton current, set vout to the voltage at node n for code = 1 (only its low n bits count) with R = 10 kΩ, and ideal to for those bits.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Simulate a capacitor charging toward = 6 V from 0 V, with = 1 ms, using Euler's method with = 0.01 ms for 1000 steps. Store the voltages in v (1001 values, starting at 0).
Vs and tau (in ms) are already defined. Work in milliseconds throughout.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Measure Euler's error. Run the discharge from 1 V over twice, with and . Set err1 and err2 to each run's largest error against the exact , and ratio to err1 / err2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An inductor L = 10 mH in series with R = 10 Ω is switched onto V = 5 V at , so . Step it with Euler's method from for 5 time constants (), with . Set i_end to the final current and err to its difference from the exact .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Euler's method steps from V with . What is after 3 steps?
Check
Simulate a discharge from 4 V, , = 1 ms, with = 0.05 ms for 400 steps. Set v (401 values).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using Euler with = 0.001 ms on a capacitor charging toward 7 V ( = 1 ms), set steps to the number of steps until first reaches 0.8 × 7 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write rk4_step(f, t, y, h) and use it to integrate from over one time constant (tau = 2) in n = 5 steps. Set v to the final value and err to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate from to with Euler and with RK4, using n = 20 and then 2 * n steps. Set ratio_euler and ratio_rk4 to (error with n steps) / (error with 2n steps) for each method.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Simulate a series RLC (R = 20 Ω, L = 10 mH, C = 1 µF) driven by a 1 V step from rest, with RK4, state [v, i], step 1 µs, for 2000 steps. Set v to the array of capacitor voltages after each step and peak to its largest value.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A pendulum of length Lp = 0.5 m obeys with = 9.81 m/s². Released from rest at th0 = 45°, integrate it with RK4 (state [theta, omega], step 1 ms) until has crossed zero going downward twice. Set T to the time between those two crossings (interpolate linearly within each step), and ratio to T divided by the small-angle period .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate from to with RK4, once with n = 5 steps (y1) and once with 2 * n (y2). For a fourth-order method, the error in y2 (that is, y2 minus the exact answer) is about . Set est to that estimate and true_err to y2 - math.exp(-1).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Use RK4 with 100 steps to integrate (a = 1) from over ; set y to the result.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two RK4 runs with step and gave y1 = 0.6065 and y2 = 0.6065. Set est to the estimated error of y2, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A resistor R = 220 Ω and a diode ( A, = 0.02585 V) are in series across Vs = 5 V. Write newton_v(v0, limit=None) from the first example, returning (v, steps). Set plain = newton_v(0.6), limited = newton_v(0.6, 2 * VT), and I to the diode current from the limited answer.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A C = 10 µF capacitor charged to V0 = 5 V discharges through 1 kΩ. Integrate the power from 0 to with the trapezoid rule on n = 160 intervals, and set E_trap, E_exact (the exact integral over the same interval, ) and rel to the relative error.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate from to with RK4 (tau = 1), starting with 5 steps and doubling the number until two successive answers differ by less than tol = 1 × 10⁻⁶. Set n to the final number of steps, v_end to that answer, and err to its true error against .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An RC ladder has R1 = 1000 Ω from a 1 V source to node 1, C1 = 47 nF from node 1 to ground, R2 = 1000 Ω from node 1 to node 2 and C2 = 22 nF from node 2 to ground. At f = 300 Hz, build the 2 × 2 complex nodal matrix (the source through R1 as a Norton current into node 1) and set v2 to the complex voltage at node 2. Then set formula to to compare.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A square wave switching between 0 and V = 5 V with period T = 1 ms and 50% duty drives an RC with tau = 1 ms. Step it exactly, with the input, using 1000 steps per period, for 40 periods from 0 V. Over the last period, set vpp to the capacitor voltage's peak-to-peak, and exact to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An RK4 simulation has an error of 5 × 10⁻⁶ with some step. What error should it have with the step 2 times smaller?
Check
A source Vs = 5 V feeds node 1 through R1 = 1000 Ω. R2 = 4700 Ω joins node 1 to node 2, and R3 = 1000 Ω and a 1 kΩ resistor go from node 2 to ground, in parallel. Node 1 also has 10 kΩ to ground. Write the nodal equations and set v to the two node voltages with np.linalg.solve.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A diode obeys with A and = 0.02585 V, in series with R = 220 Ω across Vs = 5 V. Solve for the diode voltage with bisection on to within V. Set Vd and I.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A filter's characteristic polynomial is . Set p to its roots from np.roots, stable to whether all have negative real parts, and slowest to the root's real part closest to zero.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor C = 1 µF charges toward V = 5 V through a resistor, with = 3 ms. Sample and (exact formulas) at 2001 points over , and set E to the energy delivered, , by the trapezoid rule. Compare with as E_ideal.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Charge from 0 for one time constant (tau = 1) in n = 10 steps with Euler and with RK4. Set e_euler, e_rk4 to their errors against .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Simulate a series RLC (R = 10 Ω, L = 10 mH, 1 µF) responding to a 1 V step, with RK4 at 1 µs for 20,000 steps. Set ts to the settling time in seconds: the time after which stays within 2% of 1 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using NumPy complex arithmetic, add three phasors: A = 3 at 0°, B = 4 at 120°, and 2 at −90°. Set S to the sum (a complex number), mag to its size and deg to its angle in degrees.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The arrays V and I hold ten noisy measurements of a resistor. Fit a straight line of I against V and set R_fit to the resistance it gives.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The arrays t (in ms) and v (in volts) hold a noisy capacitor discharge. Fit a line to against and set tau_fit to the time constant in ms.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A platinum RTD follows above 0 °C, with = 100 Ω. The starter has 15 noisy readings R at temperatures T (°C). Fit a quadratic with np.polyfit and set A_fit and B_fit from its coefficients.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
I (amps) and P (watts) hold noisy measurements of a resistor's power. Fit against with a degree-2 polynomial and set R_fit to its coefficient.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
x and y follow with a little noise. Fit against and set n_fit to the exponent.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write interp(x, xs, ys) for a single x inside the range of an increasing list xs: find the interval xs[i] <= x <= xs[i + 1] with bisect.bisect_right, then apply the straight-line formula. Set y = [interp(x, xs, ys) for x in queries] for the starter's table and queries.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Build a β-model thermistor table ( = 10 kΩ, β = 3950 K) from 0 to 100 °C every step = 5 °C. At T = 27.5 °C, set r_lin by interpolating linearly in temperature, r_log by interpolating against (kelvins), and err_lin, err_log to their errors in percent against the exact value.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using a 5 °C table of the same thermistor from 0 to 100 °C, set T_est to the temperature for a measured resistance of Rm = 6500 Ω by interpolating temperature against resistance, and T_exact from the β model, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter gives two loggers' records of the same signal at irregular times, (ta, va) and (tb, vb). Resample both onto a grid of whole seconds that lies inside both records, set g to that grid, d to the differences A minus B on it, and rms to the RMS of d.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A table holds = 4.7 at = 20 and = 5.8 at = 25. What does linear interpolation give at = 21?
Check
Set y to np.interp(x, [1, 2, 3, 4], [10, 20, 15, 5]) for x = 2.25, and y2 to the same value worked out with the straight-line formula yourself.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sensor's calibration table maps output voltage to pressure: 0 V → 0 kPa, 1 V → 22 kPa, 2 V → 51 kPa, 3 V → 95 kPa. Set p to the pressure for v = 1.7 V by linear interpolation.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Read the CSV text in the starter with csv.DictReader. Set names to the list of header names, n to the number of data rows, and vmax to the largest value in the v column.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Load the numeric CSV in the starter with np.loadtxt (it starts with a comment line and a header). Set t, v to its first two columns and avg to the mean of v.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The log in the starter has missing entries. Read it with np.genfromtxt and set missing to how many values are missing and means to the mean of each column, ignoring them.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Compute an RC low-pass's gain in dB at f = [10, 100, 1000, 10000] for fc = 500 Hz, and set text to CSV with the header f,gain_db and the gains to three decimal places, one row per frequency, joined with "\n".
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Each line of the starter's log looks like 12:00:05,3.301: a time of day as hh:mm:ss, then a reading. Set secs to a list of each line's time in seconds since the first line, vals to the readings as floats, and rate to the average number of readings per second over the log (lines minus one, divided by the elapsed time).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set cols to a dictionary from each header name to a list of floats for that column.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The column header says i_mA. Load the text and set i to the currents in amperes.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter simulates n = 16 noisy readings. Set m, s (sample standard deviation), sem (standard error of the mean) and ci to the half-width of an approximate 95% interval, sem.
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 readings are a mix of two groups. Set counts, edges with np.histogram(x, bins=30) and mode_center to the center of the bin with the most counts.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
You compute from V = 5 V (±0.5%) and R = 100 Ω (±5%), both independent. Set P and uP to its relative uncertainty in percent, combined in quadrature.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two instruments measure the same voltage: x1 = 3.301 V ± 0.002 V and x2 = 3.305 V ± 0.001 V. Set xw to the weighted mean and sw to its uncertainty.
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 200 readings include a few glitches. Set m and s to their mean and sample standard deviation, then clean to an array of the readings within 3 s of m, n_removed to how many were dropped, and m_clean to the mean of clean.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Readings scatter with a standard deviation of 4 mV. How many must you average to bring the standard error of the mean down to 0.5 mV or less?
Check
Readings have a standard deviation of s = 4 mV. Set n to the smallest number of readings whose standard error of the mean is at most target = 0.1 mV.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set d = a - b and ud to its uncertainty, with a = 10 ± 0.1 and b = 7 ± 0.1, independent.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
With rng = np.random.default_rng(s) and N = 100000, draw top and bottom resistors of a 10 kΩ/10 kΩ divider as uniform within ±t = 1%, top first. Set r to the array of ratios, sd to their standard deviation, and frac to the fraction within ±t/2 % 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
Model R = 10 kΩ ±tR% and C = 10 nF ±tC% as normal with = tolerance/3. With rng = np.random.default_rng(0) and 200,000 draws (R first), set fc to the corner frequencies and yld to the fraction within ±spec% of the nominal corner.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A Monte Carlo run of N = 1000 boards finds a yield of p = 0.95. Set se to the standard error of that estimate, and N4 to how many boards would halve it.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Estimate with rng = np.random.default_rng(s) and 1,000,000 points drawn as x, y = rng.uniform(-1, 1, (2, N)). Set pi_est and err to its absolute error.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An LED driver has . Model 100,000 boards with rng = np.random.default_rng(s), drawing in this order: Vs normal with mean 5 V and = 0.05 V, Vf normal with mean 2.0 V and = 0.05 V, and R uniform within ±tR = 1% of 150 Ω. Set I to the currents, yield_ to the fraction within 18 to 22 mA, and worst to the largest current.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A Monte Carlo yield estimate near 0.95 has a standard error of . How many simulated boards give a standard error of 0.5%?
Check
With rng = np.random.default_rng(s), draw 10,000 values from a normal distribution with mean 5 and standard deviation 0.1. Set p95 to the 95th percentile with np.percentile.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For two independent ±t% uniform resistors in series, set worst to the worst-case relative error of the total, in percent.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write alias(f, fs) returning the apparent frequency of a tone f sampled at fs, in the range 0 to fs/2. Set fa = alias(f, fs) for f = 7000 Hz and fs = 10000 Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter samples two tones at 8 kHz for 1600 samples. Set A to the amplitude spectrum (2 * |X| / N), f to the bin frequencies, and peaks to the sorted frequencies of the bins with amplitude above 0.1.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two tones are df = 2 Hz apart. With sample rate fs = 1000 Hz, set N to the smallest number of samples whose bin spacing is at most df, and T to the record length in seconds.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes x: a DC level plus a sine of amplitude A1 landing exactly on bin k1. From np.fft.rfft(x), set dc_est and amp_est.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes N = 1000 samples of a sine of amplitude 1 whose frequency sits at bin 50.5, between bins. Set amp_rect to the largest value of 2 * abs(np.fft.rfft(x)) / N, and amp_hann to the same for x * np.hanning(N), divided also by the Hann window's coherent gain (its mean). Then set loss_rect and loss_hann to how far each falls below 1, in dB.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A 2.5 kHz tone is sampled at 8000 samples per second for 1000 samples. Which FFT bin index (counting from 0) holds it exactly?
Check
Set nyq to the Nyquist frequency for fs = 40000 Hz, and fa to where a 30 kHz tone appears.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set f to np.fft.rfftfreq(N, 1/fs) and step to its bin spacing.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write moving_average(x, N) without np.convolve, using a cumulative sum: with c = np.cumsum(np.insert(x, 0, 0)), the sum of x[i:i + N] is c[i + N] - c[i]. Return the len(x) - N + 1 window averages. Set y = moving_average(x, N) for the starter's samples and N = 8.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Sample a 1 V sine at f = 3 Hz for 2 s at fs = 1000 Hz, pass it through an N-point moving average (N = 10, mode "valid"), and set measured to the output's amplitude, half its peak-to-peak over the last second. Set formula to from the lesson.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write smooth(x, alpha) returning the exponentially smoothed sequence, starting from y = x[0]. Feed it a unit step (100 zeros then 400 ones) sampled every 1 ms with alpha = 0.05. Set n63 to the number of samples after the step until the output first reaches 0.632, and tau_ms to the formula in ms.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write median_filter(x, w) returning the median of each window of w = 3 samples (a list w - 1 shorter than x), and use it on the starter's readings, which include some single-sample glitches. Set clean to the result and worst to its largest distance from 1.0.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A signal is sampled at 1200 Hz and carries 50 Hz hum. How many samples long must a moving average be for its first null to fall on the hum?
Check
An exponential smoother runs every 0.1 ms with = 0.05. What's its time constant?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
Set y to the N-point moving average (N = 4) of [2, 4, 6, 8, 10, 12, 14, 16] with np.convolve in "valid" mode.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Starting from y = 0, apply exponential smoothing with alpha = 0.3 to five samples of 1.0 and set y to the final output.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The CSV in the starter is a sensor calibration: temperature in °C and output in V. Fit a straight line with np.polyfit and set slope (V per °C), offset (V at 0 °C), and T_at to the temperature that gives 1.0 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The log in the starter has gaps. Read it with np.genfromtxt, then for the v column set n_good (readings present), m (their mean) and sem (their standard error, with ddof=1).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A resistance is measured as with V = 3.3 ± 0.01 V and I = 0.022 ± 0.0003 A, independent. Set R and uR (absolute, in ohms), combining the relative uncertainties in quadrature.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Model R = 4.7 kΩ ±tR% and C = 33 nF ±tC% as uniform. With rng = np.random.default_rng(7) and 100,000 draws (R first), set yld to the fraction of RC filters whose corner is within ±10% of nominal, and p5, p95 to the 5th and 95th percentiles of the corner.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes a noisy record with one hidden tone, sampled at 2 kHz for 4000 samples. Set f_peak to the frequency of the largest FFT bin, skipping DC, and amp to that bin's amplitude estimate, 2 * |X| / N.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Tones at 1, 3.5, 6, 9.2 and 13 kHz reach an ADC sampling at fs = 10000 Hz with no filter. Set aliases to the list of the frequencies (in Hz) where each appears, and clean to the list of input tones that appear at their true frequency.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes a noisy exponential decay (with in ms). Fit a straight line to against with np.polyfit, and set tau_est from its slope and V0_est from its intercept.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A pressure sensor's calibration table maps pressure (kPa) to output voltage: 0 → 0.20, 20 → 0.95, 50 → 1.90, 100 → 3.10, 150 → 3.95, 200 → 4.60 V. Using np.interp on the inverted table, set p to the pressures for the starter's readings, with np.nan for any reading outside the table's voltage range, and n_out to how many readings were outside.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter has a slow signal clean, and x, the same signal with noise and occasional large glitches. Set ma to an N-point moving average of x (5 points, "same" mode), med_ma to the same moving average applied after a 5-point median filter (pad the median's output back to full length by repeating its first and last values twice), and err_ma, err_med to each one's RMS error against clean over samples 20 to 479.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set out_frac to the fraction of the hour the frequency spends more than 0.08 Hz away from 50 Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set f_avg to the hour's 2-minute averages: an array with one mean for each block of 2 × 60 seconds.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set n_below to the number of seconds in the hour when the frequency is below 49.9 Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A part's relative error is uniform over ±t = 2%. Set sd to its standard deviation, as a fraction (), and sd_f0 to the resulting spread of a corner that depends on it through a square root.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For a unity-gain Sallen-Key with equal resistors, set Q = for C1 = 22 nF and C2 = 10 nF.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Find the RC low-pass filter's −3 dB frequency numerically: write the magnitude in dB as a function of f, and use bisection between 1 Hz and 10 MHz to find where it equals −3.0103 dB. Set f3. (Check it against .)
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An inductor current builds up as . Simulate it with Euler's method from 0 A, with a step of for 500 steps, store the currents in i (501 values), and set err to the largest difference from the exact .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor discharges through an unknown resistor. The arrays t (s) and v (V) are noisy readings, and C is known. Fit the time constant from against , then set R_fit to the resistance.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For a series RLC with R = 1000 Ω, C = 10 nF and L = 47 mH, compute the voltage across the capacitor for a 1 V input as a complex transfer function over 400 log-spaced frequencies from 100 Hz to 1 MHz. Set f_peak to the frequency of the largest gain on that grid, gain_peak to the gain there, and Q to the theoretical .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A mains current is a fundamental at f1 = 50 Hz (amplitude 1 A) plus a harmonic h = 3 times higher with amplitude a = 0.2 A, sampled at 12 kHz for exactly 10 cycles of the fundamental. From the FFT, set I1 and Ih to the two amplitudes, thd to the total harmonic distortion , and irms to the RMS current computed from the samples.
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 netlist is a list of (name, a, b, ohms) resistors with a 1 A current source into node "1" (returning through ground "0"). Build the nodal conductance matrix for the non-ground nodes (sorted by name) and set v to a dictionary from node to voltage, using np.linalg.solve.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A diode with A and = 0.02585 V is driven from V = 5 V through a resistor; sweep the resistor over 100 log-spaced values from 100 Ω to 100 kΩ. For each, find the diode voltage by bisection (to 1e-12 V) and set vd to the array of diode voltages. Then fit against with np.polyfit and set VT_fit from the slope. (Rs = 1 is not used; it's there to vary your numbers.)
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An n-th order Butterworth low-pass has . For n = 2 and fc = 300 Hz, on 500 log-spaced frequencies from to , set gdb to the gain in dB and slope to the roll-off in dB per decade measured between and (the last two decades' endpoints).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Read the CSV in the starter (a comment line, a header, then t in ms and v in mV), convert to seconds and volts, and set t, v, then vpp (peak to peak, V) and f_est: the frequency estimated from the average spacing of rising zero crossings of v - v.mean().
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate from to with RK4 in n = 50 steps and with 2 * n steps (tau = 1). Set v1, v2 to the two final values and est to the estimated error of v2, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A divider of 10 kΩ over 10 kΩ feeds an RC low-pass of 10 kΩ and 100 nF; the output is at the capacitor. Model every resistor as uniform ±tR% and the capacitor as uniform ±tC%. With default_rng(3), draw 100,000 boards (top, bottom, filter R, then C). The DC gain is the divider ratio, and the corner is where is the divider's Thevenin resistance. Set gain, fc (arrays) and yld: the fraction with gain within ±2% of 0.5 and corner within ±5% of nominal.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes a record of two tones in noise, sampled at 8 kHz for 8000 samples. Using a Hann window (np.hanning) before np.fft.rfft, set peaks to the sorted frequencies of the two largest local maxima of the spectrum's magnitude (ignoring DC).
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 Part with name, value and tol (a fraction) and a method bounds(). From the starter's list of tuples, make a list of Part objects and set widest to the name of the part with the largest absolute tolerance band (value * tol), and total to a dictionary from the first letter of each name to the sum of the nominal values with that letter.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor charges as with = 2 ms and V = 3.3 V. Find the time when it reaches th = 0.5 of V three ways: t_exact from the formula, t_bisect by bisection on [0, 20 ms] to 1e-12 s, and t_samples as the first sample time at or above the threshold on a 0.01 ms grid. All in seconds.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Compare three integrals of from 0 to 3 on n = 30 slices: left (rectangles using the left end of each slice), trap (trapezoid) and simp (Simpson). Set exact from the formula , and best to the name, "left", "trap" or "simp", of the most accurate.
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 A4