修正字典中的錯誤
你拿到一個程式,應該要遍歷菜單中的菜色,並印出名稱與其價格。
菜單的菜色儲存在下列字典中:
my_menu = {
'lasagna': 14.75,
'moussaka': 21.15,
'sushi': 16.05,
'paella': 21,
'samosas': 14
}
測試這個程式後,你發現結果不正確。
本練習屬於課程
Data Structures and Algorithms in Python
練習說明
- 修正
for迴圈中的錯誤。 - 修正
print()函式中的錯誤。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Correct the mistake
for key, value in my_menu():
# Correct the mistake
print(f"The price of the {value} is {key}.")