久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Python基于數(shù)列實(shí)現(xiàn)購(gòu)物車程序過程詳解

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

要求

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

2、用戶通過輸入編號(hào)購(gòu)買商品

3、用戶選擇商品購(gòu)買后,根據(jù)余額判斷成功或者失敗,給出對(duì)應(yīng)提示

4、可以隨時(shí)退出,退出后打印賬號(hào)余額以及購(gòu)買的商品列表

構(gòu)思

1、首先,用戶余額需要進(jìn)行存儲(chǔ),用戶購(gòu)買的物品需要進(jìn)行存儲(chǔ)在數(shù)組中

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

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

4、用戶選擇繼續(xù)后,無(wú)論成功失敗,都可以繼續(xù)購(gòu)買

代碼

# 用戶輸入工資balance = int(input('Please input balance:'))# 定義衣服的數(shù)組clothes = [['pants',100],['T-shirt',50],['skirt',20]]# 個(gè)人所得,包括金錢和獲取的物品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 # 用戶輸入商品編號(hào) code = int(input('Please choose the number:')) # 判斷錢是否夠用 if clothes[code-1][1] <= haveGoods[0]: # 在自己的購(gòu)物清單中加入已購(gòu)物品 haveGoods[1].append(clothes[code-1]) # 減去花費(fèi)的金錢 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)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 井陉县| 台南县| 专栏| 同德县| 德化县| 长岛县| 金湖县| 石狮市| 永登县| 全椒县| 凉山| 新安县| 民勤县| 阜阳市| 威远县| 灌云县| 临沧市| 秭归县| 丹巴县| 光泽县| 江陵县| 汉源县| 剑川县| 仪征市| 西峡县| 旺苍县| 云梦县| 鹤山市| 石首市| 肥城市| 青阳县| 当涂县| 怀来县| 深州市| 万盛区| 沙洋县| 中西区| 吉林市| 威信县| 惠水县| 项城市|