A4 Python for engineers · Practice
Classes and objects
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
Write 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.
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