A4 Python for engineers · Practice
Lab: parts lists, netlists and tests
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
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.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in A4