簡體   English   中英

如何獲取顯示折扣金額和折扣后購買總金額的代碼,如果需要還包括禮品包裝

[英]How to get the code to display amount of the discount & the total amount of the purchase after the discount & including the giftwrapping if needed

棒球每個售價 1.99 美元

開發一個 Python 程序,提示用戶輸入購買的棒球數量。此外,該程序應詢問用戶是否需要禮品包裝,如果需要,則在訂單中再添加 2.00 美元。

我只是想讓我的 output 提示折扣金額(如果有的話)和折扣后的購買總額,如果需要還包括禮品包裝。 但是我不知道需要什么代碼來顯示output? 所以我需要有人告訴我它是什么代碼?

Quantity  Discount
 0 - 9        0%
 10 - 50      5%
 51 or more   10%

baseballs = int(input("Enter the number of baseballs purchased: "))
if(baseballs>0):
    if baseballs<=9:
       disc = baseballs*0.00
    elif baseballs<=50:
       disc = baseballs*0.05
    elif baseballs>=51:
        disc=baseballs*0.10
        print("Discount : ",disc)
gift_wrapping = input("Do you want gift wrapping?: ")
print(baseballs + " " + "baseballs purchased" )
print(gift_wrapping)

也許是這樣的? 不是 100% 確定你在問什么:

如果您想對代碼發表評論,請告訴我。


price = 1.99
baseballs = int(input("Enter the number of baseballs purchased: "))
if(baseballs>0):
    if 0 <= baseballs <= 9:
       disc = baseballs*0.00
    elif 9 <= baseballs <= 50:
       disc = baseballs*0.05
    elif baseballs <= 51:
        disc=baseballs*0.10
        print("Discount : ",disc)
gift_wrapping = input("Do you want gift wrapping?: ")

if gift_wrapping == "yes" or "y" or "Yes":
    total = (baseballs * price) - disc + 2
else:
    total = (baseballs * price) - disc

print(str(baseballs) + " " + "baseballs purchased" )

if disc != 0:
    total_disc = total-(baseballs*price)
    print("Discount: "+str(total_disc))

print("Total price "+str(total))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM