جواب «Step 3: discount» چالش 3 از جلسهی 6
سؤال
قیمت واحد (اعشاری) و تعداد (صحیح) را بخوان. subtotal = قیمت × تعداد. اگر subtotal حداقل 1000 بود ۱۰٪ تخفیف، اگر حداقل 500 بود ۵٪، وگرنه صفر. سه خط با دو رقم اعشار چاپ کن:subtotal: 1200.00discount: 120.00total: 1080.00
راهنما
نرخ تخفیف را با if/elif/else انتخاب کن و بعد مبلغها را حساب کن.
یک جواب درست
price = float(input())
qty = int(input())
subtotal = price * qty
if subtotal >= 1000:
rate = 0.10
elif subtotal >= 500:
rate = 0.05
else:
rate = 0
discount = subtotal * rate
print(f"subtotal: {subtotal:.2f}")
print(f"discount: {discount:.2f}")
print(f"total: {subtotal - discount:.2f}")
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن