開始使用免費開始

擷取清單子集

現在你已經用兩個清單(ingredientsquantities)設定好食譜比例縮放器了,你想快速預覽採買清單。你需要從清單中取出特定項目,顯示前幾個食材及其數量,並檢查清單中最後一個項目是什麼。

本練習屬於課程

Python 入門(開發者向)

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

ingredients = ["fusilli", "tomatoes", "garlic", "basil", "olive oil", "salt"]
quantities = [500, 400, 15, 20, 30, 10]

# Get the second ingredient for your preview
second_ingredient = ____

print(second_ingredient)
編輯並執行程式碼