码迷,mamicode.com
首页 > 其他好文 > 详细

三级购物菜单

时间:2018-12-09 12:12:23      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:三级   items   center   ping   first   中兴   苹果   user   儿童   

menu = {
    ‘手机数码‘:{‘手机‘:[‘华为‘,‘中兴‘,‘苹果‘],‘数码‘:[‘相机‘,‘电脑‘]},
    ‘图书‘:{‘儿童‘:[‘连环画‘,‘童话‘],‘成人‘:[‘体育类‘,‘养生类‘]},
    ‘家电‘:{‘厨房‘:[‘电磁炉‘,‘电饭煲‘],‘客厅‘:[‘洗衣机‘,‘冰箱‘,‘电视‘]}
}
shopping_cart = []
print(‘Products list‘.center(40, ‘*‘))
i = 0
temp_menu = []
for first_menu,v in menu.items():
    temp_menu.append(first_menu)
    print(i,‘.‘,first_menu)
    i += 1
user_choice = input(‘What do you want to buy?:‘)
if user_choice.isdigit():
    user_choice = int(user_choice)
    if user_choice < len(menu):
        item2 = menu[temp_menu[user_choice]]
        a = 0
        temp_menu2 = []
        for second_menu, v in item2.items():
            temp_menu2.append(second_menu)
            print(a, ‘.‘, second_menu)
            a += 1
        user_choice2 = input(‘What do you want to buy?:‘)
        if user_choice2.isdigit():
            user_choice2 = int(user_choice2)
            if user_choice2 < len(item2):
                item3 = item2[temp_menu2[user_choice2]]
                b = 0
                for third_menu in item3:
                    print(b, ‘.‘, third_menu)
                    b += 1
                user_choice3 = input(‘What do you want to buy?:‘)
                if user_choice3.isdigit():
                    user_choice3 = int(user_choice3)
                    if user_choice3 < len(item3):
                        product = item3[user_choice3]
                        shopping_cart.append(product)
                        print("[%s] have been put into your shopping cart."%product)
                    else:
                        print("There doesn‘t have it. ")
                else:
                    print(‘Invaild data type...‘)
            else:
                print("There doesn‘t have it. ")
        else:
            print(‘Invaild data type...‘)
    else:
        print("There doesn‘t have it. ")
else:
    print(‘Invaild data type...‘)

  

三级购物菜单

标签:三级   items   center   ping   first   中兴   苹果   user   儿童   

原文地址:https://www.cnblogs.com/charliedaifu/p/10090203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!