python購物小票的案例

來源:互聯網
上載者:User

標籤:python程式

‘‘‘
資料:
T恤 tshirt 245元
運動鞋 sport 370元
網球拍 tennis 345.5元
指令:
輸入:T恤 tshirt 245元
運動鞋 sport 370元
網球拍 tennis 345.5元
輸出:總價 t && 購物小票
‘‘‘
s1=245
s2=370
s3=345.5
print("=" 25)
print("T恤:%s"%s1)
print("運動鞋:%s"%s2)
print("網球拍:%s"%s3)
print("="
25)
tshirt=int(input("T恤購買數量:"))
sport=int(input("運動鞋購買數量:"))
tennis=int(input("網球拍購買數量:"))
s=tshirt+sport+tennis
total=tshirt s1+sports2+tennis s3
if s>0:
discount=0.8 if s>2 else 1.0
total=total
discount
print("應支付 ¥%.2f"%total)
money=float(input("請繳費:"))
if money>=total:
change=money-total
print(" 消費單 ")
print("購買物品 單價 個數 金額")
print(" T恤 ¥%s %s %s"%(s1,tshirt,tshirt
s1))
print(" 網球鞋 ¥%s %s %s"%(s2,sport,sport s2))
print(" 網球拍 ¥%s %s %s"%(s3,tennis,tennis
s3))
print(" ")
print("折扣:%s折"%discount)
print("消費總金額:¥%.2f"%total)
print("實際繳費:¥%.2f"%money)
print("找錢:¥%.2f"%change)
print(" "20)
else:
print("餘額不足!")
else:
print("謝謝惠顧!")
運行結果:

python購物小票的案例

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.