python購(gòu)物車(chē)程序簡(jiǎn)單代碼
本文實(shí)例為大家分享了python購(gòu)物車(chē)程序的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
''''' Created on 2017年9月4日 @author: len ''' product_list = [ ('Robot',200000), ('MacPro',12000), ('Iphone8',8888), ('Hello World',1200), ] shopping_list = [] user_salary=input("請(qǐng)輸入你的工資:") if user_salary.isdigit(): user_salary = int(user_salary) while True: print("商品如下:") for index,item in enumerate(product_list): print (index,item) user_choice = input("請(qǐng)輸入要購(gòu)買(mǎi)的商品編號(hào):") if user_choice.isdigit(): user_choice = int(user_choice) if user_choice < len(product_list) and user_choice > -1: p_item = product_list[user_choice] if user_salary>=p_item[1]: shopping_list.append(p_item) user_salary-=p_item[1] print("購(gòu)買(mǎi)商品",p_item,"成功您的余額為",user_salary,"元!" ) else: print("您的余額為",user_salary,"余額不足以購(gòu)買(mǎi)此商品,購(gòu)買(mǎi)失??!") else: print("并無(wú)此產(chǎn)品!") elif user_choice == "q": print("--------shopping list-------") for i in shopping_list: print(i) exit() else: print("invalidate!??!")
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 使用Python的Django框架結(jié)合jQuery實(shí)現(xiàn)AJAX購(gòu)物車(chē)頁(yè)面
- Python實(shí)現(xiàn)的購(gòu)物車(chē)功能示例
- python簡(jiǎn)單商城購(gòu)物車(chē)實(shí)例代碼
- Python實(shí)現(xiàn)購(gòu)物車(chē)程序
- Python 模擬購(gòu)物車(chē)的實(shí)例講解
- Python實(shí)現(xiàn)購(gòu)物車(chē)購(gòu)物小程序
- Python初學(xué)時(shí)購(gòu)物車(chē)程序練習(xí)實(shí)例(推薦)
- Python3實(shí)現(xiàn)購(gòu)物車(chē)功能
- Python實(shí)現(xiàn)購(gòu)物車(chē)功能的方法分析
- python實(shí)現(xiàn)購(gòu)物車(chē)功能
相關(guān)文章
python代碼如何實(shí)現(xiàn)切換中英文輸入法
這篇文章主要介紹了python代碼如何實(shí)現(xiàn)切換中英文輸入法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11python KNN算法實(shí)現(xiàn)鳶尾花數(shù)據(jù)集分類(lèi)
這篇文章主要介紹了python KNN算法實(shí)現(xiàn)鳶尾花數(shù)據(jù)集分類(lèi),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10Python基于Flask框架配置依賴包信息的項(xiàng)目遷移部署
這篇文章主要介紹了Python基于Flask框架配置依賴包信息的項(xiàng)目遷移部署小技巧,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-03-03pytorch中交叉熵?fù)p失函數(shù)的使用小細(xì)節(jié)
這篇文章主要介紹了pytorch中交叉熵?fù)p失函數(shù)的使用細(xì)節(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02Python導(dǎo)入模塊時(shí)遇到的錯(cuò)誤分析
這篇文章主要給大家詳細(xì)解釋了在Python處理導(dǎo)入模塊的時(shí)候出現(xiàn)錯(cuò)誤以及具體的情況分析,非常的詳盡,有需要的小伙伴可以參考下2017-08-08jupyter notebook實(shí)現(xiàn)顯示行號(hào)
這篇文章主要介紹了jupyter notebook實(shí)現(xiàn)顯示行號(hào),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04