بتل کد Battle Codeدارد باز می‌شود…

جواب «Step 3: The Bill» چالش 3 از جلسه‌ی 12

سؤال

قدم ۳ از ۴: بعد از حلقه صورت‌حساب را بفرست: Your order:، برای هر چیز سبد یک خط - <چیز>: <قیمت> و آخر سر Total: <جمع>. جمع را با همان for حساب کن.

راهنما

total = 0 قبل از for، و داخلش total = total + prices[item].

یک جواب درست

import bot
prices = {"Pizza": 50, "Juice": 15, "Cake": 30}
print("Welcome to the School Snack Shop!")
for item in prices:
    print(f"{item}: {prices[item]}")
bot.buttons(["Pizza", "Juice", "Cake", "Done"])
cart = []
while True:
    choice = input()
    if choice == "Done":
        break
    elif choice in prices:
        cart.append(choice)
        print(f"Added {choice}.")
    else:
        print(f"We have no {choice}.")
total = 0
print("Your order:")
for item in cart:
    print(f"- {item}: {prices[item]}")
    total = total + prices[item]
print(f"Total: {total}")

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن