MulaiMulai sekarang secara gratis

Correcting bugs in a dictionary

You have been given a program that is supposed to iterate over the dishes of a menu, printing the name and its value.

The dishes of the menu are stored in the following dictionary:

my_menu = {
  'lasagna': 14.75,
  'moussaka': 21.15,
  'sushi': 16.05,
  'paella': 21,
  'samosas': 14
}

Testing the program, you realize that it is not correct.

Latihan ini adalah bagian dari kursus

Data Structures and Algorithms in Python

Lihat Kursus

Petunjuk latihan

  • Correct the mistake in the for loop.
  • Correct the mistake in the print() function.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Correct the mistake
for key, value in my_menu():
  # Correct the mistake
  print(f"The price of the {value} is {key}.")
Edit dan Jalankan Kode