MulaiMulai sekarang secara gratis

Building a dictionary

You've been working with separate lists for your recipe ingredients, quantities, and units, but you've realized that dictionaries are a better way to link everything together.

You'll now start to create a dictionary called recipe that stores each ingredient as a key and its quantity (in grams) as the value. This will make it much easier to scale your recipe for different party sizes later on.

Latihan ini adalah bagian dari kursus

Introduction to Python for Developers

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Create the recipe dictionary
recipe = {____: ____, 
# Add garlic
          ____: ____,
# Add tomatoes
          ____: ____}

print(recipe)
Edit dan Jalankan Kode