Back

Code Challenge: Backpack Weight

Difficulty  

divider

Objective

Ask the user for three items in their backpack and what each one weighs, then report the total.

Skills to Practice

  • Prompting a user for input
  • Converting input to the correct data type
  • Performing arithmetic
  • Formatting custom output using variables

Tasks

  • Create a new Python program named cc-backpack-weight.
  • Prompt for the name of item 1, then for that item's weight.
  • Use the item's name inside its weight prompt — look closely at the sample output.
  • Repeat for items 2 and 3.
  • Display each item with its weight, then the total weight.
  • Weights can be decimals, so choose your cast accordingly.

Sample Output

Sample Output
Name of item 1: Water Bottle [Enter]
Weight of Water Bottle (lbs): 1 [Enter]
Name of item 2: Laptop [Enter]
Weight of Laptop (lbs): 2 [Enter]
Name of item 3: Snack [Enter]
Weight of Snack (lbs): 0.25 [Enter]
- Weight -
Water Bottle: 1lbs
Laptop: 2lbs
Snack: 0.25lbs
Total weight: 3.25lbs

Commence Challenge