day_work_02
day_work_02
------Python是一個(gè)優(yōu)雅的大姐姐
作業(yè)一
?
?
設(shè)計(jì)思路(四個(gè)if一個(gè)while)
?
運(yùn)行代碼
# Author:Xiong
product_list=[
??? ('iphone6s',5800),
??? ('macbook',9000),
??? ('coffee',30),
??? ('python book',80),
??? ('bicyle',1500),
]
shopping_car = []
salary = input('請輸入您的薪水:')
for i,v in enumerate(product_list,1):
??? print(i,v[0],v[1])
if salary.isdigit():
??? save = int(salary)
??? while True:
??????? ch = input('輸入您需要購買的商品編號(hào)[q退出]')
??????? if ch.isdigit():
??????????? ch = int(ch)
??????????? if ch>0 and ch <= len(product_list):
??????????????? if product_list[ch-1][1] > save:
??????????????????? print('余額不足,',save - product_list[ch-1][1])
??????????????? else:
??????????????????? save -= product_list[ch-1][1]
??????????????????? print('購買%s成功!當(dāng)前余額%d'%(product_list[ch-1],save))
??????????????????? shopping_car.append(product_list[ch-1])
??????????? else:
??????????????? print('不存在該商品編號(hào)!')
??????? elif ch == 'q':
??????????? print('購買商品為%s' % shopping_car)
??????????? print('余額為%d' % save)
??????????? print('歡迎下次光臨!')
??????????? break
??????? else:
??????????? print('輸入錯(cuò)誤!')
else:
?? print('輸入薪水不為數(shù)字!')
?
運(yùn)行結(jié)果
?
?
作業(yè)二
?
?
設(shè)計(jì)思路
exit_flag = False:終結(jié)循環(huán)的標(biāo)志,本程序未設(shè)置退出程序操作。
current_layer = menu:
layers = [menu]:
?
運(yùn)行代碼
menu = {
??? '北京':{
??????? '海淀':{
??????????? '五道口':{
??????????????? 'soho':{},
??????????????? '網(wǎng)易':{},
??????????????? 'google':{}
??????????? },
??????????? '中關(guān)村':{
??????????????? '愛奇藝':{},
??????????????? '汽車之家':{},
??????????????? 'youku':{},
??????????? },
??????????? '上地':{
??????????????? '百度':{},
??????????? },
??????? },
??????? '昌平':{
??????????? '沙河':{
??????????????? '老男孩':{},
??????????????? '北航':{},
??????????? },
??????????? '天通苑':{},
??????????? '回龍觀':{},
??????? },
??????? '朝陽':{},
??????? '東城':{},
??? },
??? '上海':{
??????? '閔行':{
??????????? "人民廣場":{
??????????????? '炸雞店':{}
??????????? }
??????? },
??????? '閘北':{
??????????? '火車戰(zhàn)':{
??????????????? '攜程':{}
??????????? }
??????? },
??????? '浦東':{},
??? },
}
exit_flag = False
current_layer = menu
layers = [menu]
while not? exit_flag:
??? for k in current_layer:
??????? print(k)
??? choice = input(">>(輸入b返回上一級(jí)):").strip()
??? if choice == "b":
??????? current_layer = layers[-1]
??????? layers.pop()
??? elif choice not? in current_layer:continue
??? else:
??????? layers.append(current_layer)
??????? current_layer = current_layer[choice]
運(yùn)行結(jié)果
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/xzmxddx/p/8365413.html
總結(jié)
以上是生活随笔為你收集整理的day_work_02的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring实战(三)Spring中装配
- 下一篇: 信号的发送