1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Python for Developers

Connected

Exercise

Looping with a dictionary

Your recipe scaler is coming together! You have a dictionary called recipe that contains ingredient names as keys and their quantities in grams as values for your tomato and basil pasta. Now you need to scale all the quantities by a factor of 2 to serve more guests at your party. You'll loop through the dictionary items and calculate the scaled quantities.

Instructions

100 XP
  • Use a for loop to iterate through the recipe dictionary, using ingredient and qty as your iterators.
  • Inside the loop, create a variable called scaled_qty that multiplies the original quantity by the scaling factor of 2.