python 商品購物車

來源:互聯網
上載者:User

標籤:car   exit   app   商品   enumerate   選擇   lease   put   pos   

 1 Shopping_Cart=[] 2  3 commodity=[("iphone",5000), 4 ("bike",200), 5 ("book",100), 6 ("computer",3000), 7 ("car",10000), 8 ] 9 salary=input("please input your salary:")10 11 # print(commodity)12 if salary.isdigit():13     salary=int(salary)14     while True:15         for index,item in enumerate(commodity):16             print(index,item)17         Use_choice = input("please choose you want to buy commodity num:")18         if Use_choice.isdigit():19             Use_choice=int(Use_choice)20             if Use_choice<len(commodity) and Use_choice>=0 :21                 p_item=commodity[Use_choice]22                 # print(p_item[1])23                 if p_item[1]<= salary:24                     Shopping_Cart.append(p_item)25                     salary-=p_item[1]26                     print("Shopping_Cart added %s ,your current balance is \033[31;1m %s \033[0m" % (p_item,salary))27                 else :28                     print("\033[41;1m 餘額不足,請重新選擇 %s \033[0m" %salary)29             else:30                 print("please iput correct product code \033[31;1m %s \033[0m" % Use_choice)31         elif Use_choice=="q" :32             print("--------shopping list---------")33             for i in Shopping_Cart:34                 print(i)35             exit("成功退出購買商品")36         else:37             print("please input Correct commodinty num \033[31;1m %s \033[0m"%Use_choice)38 else:39     print("\033[31;1mplease input Correct salary %s \033[0m"%salary)

 

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.