python實現購物車:新手版

來源:互聯網
上載者:User

標籤:餘額   pytho   images   app   不能   程式   允許   http   技術分享   

#!/user/bin/env python
#一個購物車的程式
‘‘‘需求:
啟動購物車,讓使用者輸入工資,然後列印商品列表
允許使用者根據商品編號購買商品
使用者選擇商品後,檢測餘額是否夠,夠就直接扣款,否則提醒
可以隨時退出,退出時列印已購買商品和餘額‘‘‘

sal=input("請輸入你的工資:")
show=[("car","1000"),("dog","2000"),("cat","100"),("ball","200")]
show_card=[]
title = "True"

if sal.isdigit():
sal=int(sal)
now_salary = sal
while title:
for i in show:
print(show.index(i), i)
choose = int(input("選擇你的商品序號:"))
if sal >= int(show[choose][1]):
print("3Q,你已成功購買的商品:", show[choose][0])
show_card.append(show[choose])
now_salary -= int(show[choose][1])
result = input("繼續購買商品嗎?按q退出或者按任意鍵繼續")
if result == "q":
print("你的商品有:%s ,你的餘額為:%s" % (show_card, now_salary))
break
else:
continue
else:
print("你的工資並不能購買這個商品")
break
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.