day2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了day2相关的知识,希望对你有一定的参考价值。
#模拟三级菜单 menu = { ‘河南省‘: { ‘郑州‘: { ‘嵩山少林寺‘: {}, ‘伏羲山大峡谷‘: {}, ‘城隍庙‘: {} }, ‘三门峡‘: { ‘天鹅湖‘: {}, ‘函谷关‘: {}, ‘虢国车马坑‘: {} }, ‘洛阳‘: { ‘龙门石窟‘: {}, ‘白马寺‘: {}, ‘牡丹园‘: {} } }, ‘陕西省‘: { ‘西安‘: { ‘秦始皇兵马俑‘: {}, ‘大雁塔‘: {}, ‘华山‘: {} }, ‘汉中‘: { ‘武侯祠‘: {}, ‘朱鹮生态园‘: {}, ‘天台国家森林公园‘: {} }, ‘太原‘: { ‘晋祠公园‘: {}, ‘东湖醋园‘: {}, ‘汾河公园‘: {} } }, ‘台湾‘: { ‘台北‘: { ‘中正纪念堂‘: {}, ‘西门町‘: {}, ‘士林官邸‘: {} }, ‘高雄‘: { ‘西子湾风景区‘: {}, ‘六合夜市‘: {}, ‘爱河‘: {} }, ‘基隆‘: { ‘基隆屿‘: {}, ‘奠济宫‘: {}, ‘湖净公园‘: {} } }, ‘海南省‘:{ ‘海口‘: { ‘热带野生动植物园‘: {}, ‘假日海滩旅游区‘: {}, ‘仙人洞‘: {}, }, ‘三亚‘: { ‘天涯海角‘: {}, ‘椰梦长廊‘: {}, ‘亚龙湾热带天堂森林公园‘: {}, }, ‘儋州‘: { ‘东坡书院‘: {}, ‘石花水洞地质公园‘: {}, ‘鹭鸶公园‘: {}, } } } exit_flag = False #定义变量条件,改变条件程序结束 current_layer = menu #current可以表示为函数的符号,也可以理解为计算机操作命令 layers = [menu] #layers表示层次 while not exit_flag: for k in current_layer: print(k) choice = input(">>:").strip() if choice == "back": current_layer = layers[-1] #输入back时,返回上级菜单 #print(current_layer) layers.pop() #print(layers.pop()) elif choice not in current_layer: #print(‘Please inter back‘) continue else: layers.append(current_layer) current_layer = current_layer[choice]
模拟购物车
import getpass,msvcrt,sys fruit_menu = { ‘apple‘:10, ‘car‘:100000, ‘mac‘:8000, ‘bed‘:500, ‘beef‘:30 } count = 0 while count <= 3: count += 1 in_acc = input(‘name: ‘) in_pwd = input(‘password: ‘) if in_acc == ‘dhd‘ and in_pwd == ‘123‘: print(‘welcome dhd !!!‘) buy_list = [] while True: for key,item in fruit_menu.items(): #for key,item in fruit_menu.items(): print(‘name:{name} price:{price}‘.format(price=item,name=key)) #print(‘name:{name} price:{price}‘.format(price=item,name=key)) choice = input(‘商品>>: ‘).strip() if not choice or choice not in fruit_menu:continue count = input(‘购买个数>>: ‘).strip() if not count.isdigit():continue buy_list.append((choice,fruit_menu[choice],count)) print(buy_list) break else: if count < 3: print(‘Please Input agin !‘) if count == 3: print(‘worong 3 times, Please call 110 !‘) break
以上是关于day2的主要内容,如果未能解决你的问题,请参考以下文章