整体案例打包了,有兴趣下载看看
链接:https://pan.baidu.com/s/1pM6PcKoAQ2LaXiMc79_9RQ
提取码:usuq 复制这段内容后打开百度网盘手机App,操作更方便哦
手机淘宝主程序:
1 from main1 import account 2 import time 3 4 5 print("\t""\t", "-" * 10, "欢迎进入手机淘宝", "-" * 10, "\t""\t") 6 user_account = {} 7 new_user_account = {} 8 while True: 9 print("\t", "*" * 5, "编码 1 ---登录", "*" * 5, "\t") 10 print("\t", "*" * 5, "编码 2 ---注册", "*" * 5, "\t") 11 print("\t", "*" * 5, "编码 3 ---退出", "*" * 5, "\t") 12 user_set = int(input("输入编码")) 13 # 登录 14 if user_set == 1: 15 a = account.denglu() 16 # 获取account.py的 denglu 函数 17 if a[1].get(a[2]) == a[3]: 18 a[0].close() 19 print("登录成功") 20 break 21 else: 22 a[0].close() 23 print("用户或密码错误") 24 #注册 25 if user_set == 2: 26 a = account.zhuce() 27 # 获取account.py的 zhuce 函数 28 if a[4] == None: 29 user_password = input("请输入密码") 30 user_account.update(a[0]) 31 new_user_account.setdefault(a[3], user_password) 32 user_account.update(new_user_account) 33 file = open(a[2], "w") 34 file.write(str(user_account)) 35 file.close() 36 print("注册成功") 37 else: 38 print("用户名已被注册") 39 #退出 40 if user_set == 3: 41 print("退出成功") 42 break 43 time.sleep(1) 44 from buy import buy 45 num_a = 0 46 while True: 47 print("\t""\t", "-" * 10, "欢迎进入手机淘宝", "-" * 10, "\t""\t") 48 print("\t", "*" * 5, "编码 1 ---今日特卖", "*" * 5, "\t") 49 print("\t", "*" * 5, "编码 2 ---女士服装", "*" * 5, "\t") 50 print("\t", "*" * 5, "编码 3 ---男士服装", "*" * 5, "\t") 51 print("\t", "*" * 5, "编码 4 ---美食茶酒", "*" * 5, "\t") 52 print("\t", "*" * 5, "编码 5 ---结算", "*" * 5, "\t") 53 user_items = input("输入编码") 54 while True: 55 #今日特卖 56 if user_items == "1": 57 print("\t", "*" * 3, "编码 1 毛衣 59元", "*" * 3, "\t") 58 print("\t", "*" * 3, "编码 2 运动鞋 69元", "*" * 3, "\t") 59 print("\t", "*" * 3, "编码 3 运动鞋 99元", "*" * 3, "\t") 60 user_item = input("请输入商品编号") 61 #选择 1 62 if user_item == "1": 63 a = buy.item1() 64 if a == "y": 65 continue 66 else: 67 buy.turn() 68 break 69 # 选择 2 70 if user_item == "2": 71 a = buy.item2() 72 if a == "y": 73 continue 74 else: 75 buy.turn() 76 break 77 78 # 选择 3 79 if user_item == "3": 80 a = buy.item3() 81 if a == "y": 82 continue 83 else: 84 buy.turn() 85 break 86 #女士服装 87 if user_items == "2": 88 print("\t", "*" * 3, "编码 1 女装 59元", "*" * 3, "\t") 89 user_item = input("请输入商品编号") 90 if user_item == "1": 91 a = buy.girl1() 92 if a == "y": 93 continue 94 else: 95 buy.turn() 96 break 97 #男士服装 98 if user_items == "3": 99 print("\t", "*" * 3, "编码 1 男士 59元", "*" * 3, "\t") 100 user_item = input("请输入商品编号") 101 if user_item == "1": 102 a = buy.man1() 103 if a == "y": 104 continue 105 else: 106 buy.turn() 107 break 108 #美食茶酒 109 if user_items == "4": 110 print("\t", "*" * 3, "编码 1 咖啡 50元", "*" * 3, "\t") 111 print("\t", "*" * 3, "编码 2 零食大礼包 69元", "*" * 3, "\t") 112 print("\t", "*" * 3, "编码 3 柠檬 30元", "*" * 3, "\t") 113 user_item = input("请输入商品编号") 114 #选择1 115 if user_item == "1": 116 a = buy.shiwu() 117 if a == "y": 118 continue 119 else: 120 buy.turn() 121 break 122 if user_item == "2": 123 a = buy.shiwu1() 124 if a == "y": 125 continue 126 else: 127 buy.turn() 128 break 129 if user_item == "3": 130 a = buy.shiwu2() 131 if a == "y": 132 continue 133 else: 134 buy.turn() 135 break 136 #结算 137 num_a = 0 138 if user_items == "5": 139 a = buy.jiezhan() 140 buy.turn1() 141 print("本次消费共", a) 142 num = input("谢谢,继续按W,退出按0") 143 if num == "w": 144 buy.tui() 145 break 146 if num == "0": 147 num_a += 1 148 break 149 if num_a == 1: 150 break
购买函数
1 #返回上一级 2 item = [] 3 def turn(): 4 num = 0 5 print("当前已有商品") 6 for i in item: 7 num += 1 8 if num & 1: 9 print(i, "\t", end="") 10 else: 11 print(i, "元\t") 12 13 input("输入n 返回上一级") 14 15 #1今日特卖 16 def item1(): 17 item.append("毛衣") 18 item.append(59) 19 yes_or_no = input("购买成功,是否继续y/n") 20 return yes_or_no 21 #今日特卖 22 def item2(): 23 item.append("运动鞋") 24 item.append(69) 25 yes_or_no = input("购买成功,是否继续y/n") 26 return yes_or_no 27 #今日特卖 28 def item3(): 29 item.append("风衣") 30 item.append(99) 31 yes_or_no = input("购买成功,是否继续y/n") 32 return yes_or_no 33 #2女士 34 def girl1(): 35 item.append("女装") 36 item.append(59) 37 yes_or_no = input("购买成功,是否继续y/n") 38 return yes_or_no 39 #3男士 40 def man1(): 41 item.append("男士") 42 item.append(59) 43 yes_or_no = input("购买成功,是否继续y/n") 44 return yes_or_no 45 46 47 48 #4食物 49 def shiwu(): 50 item.append("咖啡") 51 item.append(50) 52 yes_or_no = input("购买成功,是否继续y/n") 53 return yes_or_no 54 #食物 55 def shiwu1(): 56 item.append("零食大礼包") 57 item.append(69) 58 yes_or_no = input("购买成功,是否继续y/n") 59 return yes_or_no 60 #食物 61 def shiwu2(): 62 item.append("柠檬") 63 item.append(30) 64 yes_or_no = input("购买成功,是否继续y/n") 65 return yes_or_no 66 #5结账 67 def jiezhan(): 68 money = 0 69 num = 0 70 for i in item: 71 if num & 1: 72 money = money + i 73 else: 74 pass 75 num += 1 76 return money 77 #退出 78 def tui(): 79 item.clear() 80 81 #统计商品 82 def turn1(): 83 num = 0 84 print("当前已有商品") 85 for i in item: 86 num += 1 87 if num & 1: 88 print(i, "\t", end="") 89 else: 90 print(i, "元\t")
登录界面
#登录 def denglu(): print("*欢迎来的登录页面*") user_name = input("请输入用户名") user_password = input("请输入密码") path = r"C:\Users\Administrator\Desktop\aaa.txt" file = open(path, "r") data = eval(file.read()) return file,data,user_name,user_password # 注册 def zhuce(): print("*注册页面*") user_name = input("请输入用户名") path = r"C:\Users\Administrator\Desktop\aaa.txt" file = open(path, "r+") date = eval(file.read()) user_password = date.get(user_name) file.close() return date, file, path, user_name, user_password