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

جواب «Step 4: Pay and Change» چالش 4 از جلسه‌ی 12

سؤال

قدم ۴ از ۴: درست بعد از خوش‌آمد بپرس How much money do you have? و جواب را عدد کن (money). آخر کار، اگر جمع از پول کمتر یا مساوی بود بگو Paid! Your change: <بقیه‌ی پول> وگرنه Not enough money. You need <چقدر کم است> more..

راهنما

سؤال و money = int(input()) را زیر خط خوش‌آمد بگذار. آخر کار if total <= money:.

یک جواب درست

import bot
prices = {"Pizza": 50, "Juice": 15, "Cake": 30}
print("Welcome to the School Snack Shop!")
print("How much money do you have?")
money = int(input())
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}")
if total <= money:
    print(f"Paid! Your change: {money - total}")
else:
    print(f"Not enough money. You need {total - money} more.")

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