Question: Problem 4. Consider a data type weight that models weights used in a weighing (balance) scale, and supports the following API description constructs a weight
Problem 4. Consider a data type weight that models weights used in a weighing (balance) scale, and supports the following API description constructs a weight w with given value and units constructor/method Weight (value, v.value(O returns the value of v.convert (units, cfactor) converts to the given units using the given conversion factor returns a new weight with value that is c times the value of returns True if v and v have the same value and units, and False otherwise returns a string representation of v str(u) a. Which of the following code fragments correctly sets up a list a of 20 distinct veight objects, each with weight 2 lb? A. a - [Weight (2) for 1 in range (20)1 B. a - [Weight (2)] 20 C. a - [Weight (2, '1b')] 20 D. a [Weight (2, '1b') for i in range (20)1 E. a [eight (2, "1b') for i in range(19)1 b. Which of the following code fragments correctly converts the 15th weight in a to kg (1 kg 2.2 lb)? A. a[14].convert('kg, 2.2) B. a (14).convert('kg', 1/ 2.2) C. a[15].convert ('kg', 1/2.2) D. a(15).convert(kg, 2.2) E. a.convert (14, 'kg', 1/2.2) c. Which of the following code fragments correctly prints the string representation of the 13th weight in a? A. atdout.vriteln(a (12].str)) Initials: 5 of 9
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
