Two test runs contain equally weighted torque readings in N⋅m\text{N}\cdot\text{m}N⋅m:
runs = [[2.0, 4.0], [6.0, 8.0, 10.0]]
A function is intended to return one independent mean for each run, but currently combines state across runs:
def run_means(runs): total = 0.0 count = 0 means = [] for run in runs: for value in run: total += value count += 1 means.append(total / count) return means
Which reset strategy gives the intended independent means? In each proposed change, any reset inside the outer loop occurs immediately before the inner loop, and all other statements remain as shown.
Reset neither variable for each run; return [3.0, 6.0].
Reset both total and count for every run; return [3.0, 8.0].
Reset only count for every run; return [3.0, 10.0].
Reset only total for every run; return [3.0, 4.8].
Unlock full course notes by signing up
Reproduce a simulated error sequence
An engineering simulation uses a pseudorandom number generator to model measurement errors. Two runs use the same generator algorithm and software version and request draws in exactly the same order.
Complete the explanation using the appropriate programming terms.
To reproduce the sequence from its beginning, each run creates a fresh generator initialized with the same integer ________. Reusing an existing generator after it has already supplied draws generally continues from its current internal ________, rather than restarting the sequence.
Preserve the original force readings
An engineer stores three force readings in newtons in a Python list. Before calculating a summary, a temporary calculation adds 4 N to the second reading and removes the final reading.
Execute each experiment independently, starting with its own list. Complete the table with exact integers. List indices start at zero, and pop() without an argument removes the final element.
Experiment A
Repair weighting and early return
An instrument draws constant power within each of three successive intervals:
80 W80\ \text{W}80 W for 2.0 s2.0\ \text{s}2.0 s;
140 W140\ \text{W}140 W for 1.0 s1.0\ \text{s}1.0 s;
Compare two window-total implementations
A vibration-analysis program needs the total acceleration reading in every complete window of 12 consecutive samples from a list of 240 samples. The following Python implementations calculate those window totals. You are comparing their computational cost, rather than interpreting the totals physically.
Use this simplified cost model: count only executions of the marked addition or subtraction in each implementation. Each marked operation costs one unit. Ignore indexing, assignment, loop control, list operations and all other arithmetic, including arithmetic inside range and indices. Python's range(a, b) includes a and excludes b.
Direct implementation