三级购物菜单

Posted charliedaifu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三级购物菜单相关的知识,希望对你有一定的参考价值。

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...‘)

  

以上是关于三级购物菜单的主要内容,如果未能解决你的问题,请参考以下文章

python-三级菜单和购物车程序

三级菜单模拟登陆购物车等作业

python--------三级菜单以及购物车实现

Day3.三级菜单+购物车打印格式优化

三级购物菜单

三级菜单和购物车