自己写的一个简单的购物车的登录购买

注释掉的是每天都敲的任务,下面的是自己没事写的,特别的简单的,根据自己学的写的。

# menu = {
#     '北京': {
#         '海淀': {
#             '五道口': {
#                 'soho': {},
#                 '网易': {},
#                 'google': {}
#             },
#             '中关村': {
#                 '爱奇艺': {},
#                 '汽车之家': {},
#                 'youku': {},
#             },
#             '上地': {
#                 '百度': {},
#             },
#         },
#         '昌平': {
#             '沙河': {
#                 '老男孩': {},
#                 '北航': {},
#             },
#             '天通苑': {},
#             '回龙观': {},
#         },
#         '朝阳': {},
#         '东城': {},
#     },
#     '上海': {
#         '闵行': {
#             "人民广场": {
#                 '炸鸡店': {}
#             }
#         },
#         '闸北': {
#             '火车战': {
#                 '携程': {}
#             }
#         },
#         '浦东': {},
#     },
#     '山东': {},
# }
# tag = True
# while tag:
#     menu1 = menu
#     for key in menu1:
#         print(key)
#     choicel = input('第一层:>>').strip()
#
#     if choicel == 'b':
#         print('到顶了,你得选择下面的:')
#         continue
#     if choicel == 'q':
#         tag = False
#         continue
#     if choicel not in menu1:
#         print('输错了')
#         continue
#
#     while tag:
#         menu2 = menu1[choicel]
#         for key in menu2:
#             print(key)
#
#         choicel = input('第二层:>>').strip()
#
#         if choicel == 'b':
#             break
#         if choicel == 'q':
#             tag = False
#             continue
#         if choicel not in menu2:
#             print('输错了')
#             continue
#
#         while tag:
#             menu3 = menu2[choicel]
#             for key in menu3:
#                 print(key)
#             choicel = input('第三层:>>').strip()
#
#             if choicel == 'b':
#                 break
#             if choicel == 'q':
#                 tag = False
#                 continue
#             if choicel not in menu3:
#                 print('输错了')
#                 continue
#
#             while tag:
#                 menu4 = menu3[choicel]
#                 for key in menu4:
#                     print(key)
#                 choicel = input('第四层:>>').strip()
#                 if choicel == 'q':
#                     tag = False
#                     continue
#                 if choicel == 'b':
#                     break
#                 if choicel not in menu4:
#                     print('输错了')
#                     continue
product_list = [
    ['Iphone7', 5800],
    ['Coffee', 30],
    ['疙瘩汤', 10],
    ['Python Book', 99],
    ['Bike', 199],
    ['ViVo X9', 2499],
]
name_list = []
menu_dic = {}
buy_list = []
username_pwd = [{'xxx': '12'}, {'rui': '222'}]
# pwd = '123'
count = 0
tag3 = True
tag2 = True
tag1 = True
tag = True
sum_price = 0
while tag2:
    print('{:-^20}'.format('>登录<'))
    print('{:-^20}'.format('>注册<'))
    print('{:-^20}'.format('如果没有账号请注册'))
    choose_login_register = input("请选择你要进行的操作:>>").strip()
    if choose_login_register == '登录':
        while tag1:
            inp_username = input('请输入用户名:').strip()
            inp_pwd = input('请输入密码:').strip()
            if {inp_username: inp_pwd} in username_pwd:
                while tag:
                    for i in product_list:
                        x, y = i
                        menu_dic[x] = y
                        name_list.append(x)
                        print(f'商品名:{x}--¥:{y}')
                    print(f'购物车里面的商品:{buy_list}')
                    choose = input('将你想要的添加到购物车:>>').strip()
                    if choose == '结算':
                        # tag = False
                        break
                    if choose in name_list:
                        buy_list.append(choose)
                    else:
                        print('请输入正确的商品名')
                        continue
                for j in buy_list:
                    sum_price = sum_price + int(menu_dic[j])
                print(f'您需要支付:¥{sum_price}元')
                # zhifubao = input("请输入您的支付宝账户").strip()
                tag1 = False
                continue
            else:
                if count == 2:
                    print('没次数了')
                    break
                print(f'输入错误,你还有{2 - count}次机会')
                count += 1
    elif choose_login_register == '注册':
        while tag3:
            username_pwd_cop = username_pwd.copy()
            for k in username_pwd:
                if len(username_pwd_cop) < len(username_pwd):
                    tag3 = False
                    break
                user_register = input("请输入您的账号:>>").strip()
                for xc_key, xc_value in k.items():
                    if xc_key == user_register:
                        print("已存在用户名,请重新输入")
                        break
                    else:
                        pwd_register = input("请输入密码:>>").strip()
                        pwd_register_again = input("请再次输入密码:>>").strip()
                        if pwd_register == pwd_register_again:
                            username_pwd.append({user_register: pwd_register})
                            print('注册成功!')
                            break
                        else:
                            print('两次输入不一样')
                            continue
    elif choose_login_register == 'q':  # 不想登录输入q
        break
    else:
        print("您输入错误的选项辣!")