An engineer intends to double three loads, measured in kN, and checks the results by comparing their totals:
import numpy as np F_list = [2.0, 4.0, 6.0] # loads, kN F_arr = np.array(F_list) a = F_list * 2 b = F_arr * 2 if sum(a) == np.sum(b): result = (len(a), float(np.mean(a)), float(np.mean(b))) else: result = None
What value does result hold, and what does it reveal about the engineer's check? The tuple contains the number of elements in a, the mean of a in kN, and the mean of b in kN, respectively.
(3, 8.0, 8.0); the matching totals confirm that both operations doubled each load.
A TypeError occurs before result is assigned because the list contains floats.
(6, 4.0, 8.0); the matching totals fail to detect that the list repeated its loads.
None; the different lengths make the totals unequal, so the check detects the problem.
Unlock full course notes by signing up
Pump energy from sliced arrays
A data logger records a pump's average power over four consecutive intervals. An engineer computes energy with this code:
What value does E hold? Give your answer in kWh to two decimal places.
Splitting a test duration with // and %
A data logger records the duration of a fatigue test as an integer number of seconds. A Python script splits it into hours, minutes and seconds, and also computes one extra value r:
Give the value that Python stores in each of h, m, s and r. Each answer is an exact integer.
Writing a vectorized RMS function
An oscilloscope records these voltage samples across a resistor:
The root-mean-square value of NNN samples is
Ranking expressions by operator precedence
Each item below is a complete Python expression typed at the interpreter. Evaluate each one using Python's operator precedence and associativity rules, then arrange the expressions from the smallest resulting value to the largest.