Trace selection and output separately

A shipping program calculates a charge of 3 US dollars per kilogram for packages whose mass is at least 5 kilograms:


Python
masses = [2, 5, 8, 11]
charges = [3 * mass for mass in masses if mass >= 5]


Complete the trace table. Enter yes or no for whether each source item is kept. For its output contribution, enter an exact integer charge in US dollars or the word skipped when it contributes no element.

Source mass (kg)Kept?Output contribution (USD or skipped)
2
5
8
11

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More List Comprehensions Questions: