国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Python基于數列實現購物車程序過程詳解

瀏覽:5日期:2022-07-22 08:52:41

要求

1、啟動程序后讓用戶輸入余額,并打印商品列表

2、用戶通過輸入編號購買商品

3、用戶選擇商品購買后,根據余額判斷成功或者失敗,給出對應提示

4、可以隨時退出,退出后打印賬號余額以及購買的商品列表

構思

1、首先,用戶余額需要進行存儲,用戶購買的物品需要進行存儲在數組中

2、用戶購買成功后,將購買的物品放入物品集合,并用總金額減去余額

3、如果失敗,給出失敗提示,并打印余額

4、用戶選擇繼續后,無論成功失敗,都可以繼續購買

代碼

# 用戶輸入工資balance = int(input('Please input balance:'))# 定義衣服的數組clothes = [['pants',100],['T-shirt',50],['skirt',20]]# 個人所得,包括金錢和獲取的物品haveGoods = [balance,[]]flag = Truewhile flag: # 打印衣服列表 print('The clothes list is as follows') print('______clothesList______') i = 1; for c in clothes: print(’The number:’,i,':',c) i += 1 # 用戶輸入商品編號 code = int(input('Please choose the number:')) # 判斷錢是否夠用 if clothes[code-1][1] <= haveGoods[0]: # 在自己的購物清單中加入已購物品 haveGoods[1].append(clothes[code-1]) # 減去花費的金錢 haveGoods[0] -= clothes[code-1][1] print('You have successfully purchased!') print('Your account balance is:',haveGoods[0]) else: print('Your account balance is insufficient!') print('Your account balance is:',haveGoods[0]) judge = input('You can press any button to continue,or input ’n’ to leave:') if judge == 'n': flag = Falseprint('Your account balance is:',haveGoods[0])print('Your shopping list is as follows:')print('______clothesList______')for h in haveGoods[1]: print(h)

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 太湖县| 武宣县| 长宁县| 阿坝县| 宝应县| 苍山县| 许昌县| 正阳县| 无棣县| 三明市| 广灵县| 腾冲县| 莱阳市| 安平县| 白朗县| 手游| 南乐县| 东莞市| 密云县| 利辛县| 潮安县| 上杭县| 家居| 同德县| 井陉县| 南投市| 镇原县| 龙州县| 上高县| 房山区| 开阳县| 正镶白旗| 于田县| 左贡县| 东乡县| 宁南县| 丁青县| 延安市| 千阳县| 张家界市| 平遥县|