python購物車程序簡單代碼
更新時間:2018年04月18日 10:21:46 作者:不會代碼的程序員
這篇文章主要為大家詳細介紹了python購物車程序的簡單代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了python購物車程序的具體代碼,供大家參考,具體內(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("請輸入你的工資:")
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("請輸入要購買的商品編號:")
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("購買商品",p_item,"成功您的余額為",user_salary,"元!" )
else:
print("您的余額為",user_salary,"余額不足以購買此商品,購買失??!")
else:
print("并無此產(chǎn)品!")
elif user_choice == "q":
print("--------shopping list-------")
for i in shopping_list:
print(i)
exit()
else:
print("invalidate?。?!")
效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python KNN算法實現(xiàn)鳶尾花數(shù)據(jù)集分類
這篇文章主要介紹了python KNN算法實現(xiàn)鳶尾花數(shù)據(jù)集分類,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
pytorch中交叉熵損失函數(shù)的使用小細節(jié)
這篇文章主要介紹了pytorch中交叉熵損失函數(shù)的使用細節(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02

