嵌套 购物车 登录注册
Posted 200ML
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了嵌套 购物车 登录注册相关的知识,希望对你有一定的参考价值。
省市 dict_1 = { ‘湖南‘:{ ‘长沙‘:[‘岳麓‘,‘天心‘,‘开服‘,‘南站‘], ‘株洲‘:[‘荷塘‘,‘河西‘], }, ‘广东‘:{ ‘广州‘:[‘天河‘,‘白云‘,‘番禺‘], ‘深圳‘:[‘保安‘,‘福田‘,‘罗湖‘], } } isexit = False while not isexit: for i1 in dict_1: print(i1) u1 = input(‘请输入您想旅游的省:‘) if u1 in dict_1: while not isexit: for i2 in dict_1[u1]: print(i2) u2 = input(‘请输入您想旅游的市‘) if u2 in dict_1[u1]: while not isexit: for i3 in dict_1[u1][u2]: print(i3) u3 = input(‘请输入您想旅游的目的地:‘) if u3 in dict_1[u1][u2]: print(‘恭喜你,已经到达目的地‘%s’‘%u3) print(‘请按B退出‘) u4 = input(‘‘) if u4 == ‘B‘ or u4 == ‘b‘: isexit = True elif u4 == ‘c‘ or u4 == ‘C‘: break elif u2 == ‘B‘ or u2 == ‘b‘: isexit = True elif u2 == ‘c‘ or u2 == ‘C‘: break elif u1 == ‘B‘ or u1 == ‘b‘: isexit = True
购物车 shopping = [ {‘name‘:‘电脑‘,‘price‘:15}, {‘name‘:‘鼠标‘,‘price‘:100}, {‘name‘:‘键盘‘,‘price‘:25}, {‘name‘:‘耳机‘,‘price‘:200}, ] num = 1 shop_car={} isexit = False money_1 = input(‘请输入资产:‘) money = int(money_1) money_2 = int(money_1) money_3=[] for i in shopping: print(i[‘name‘],i[‘price‘]) while not isexit: inp_1 = input(‘请输入需要购买的商品y退出:‘) if inp_1 == ‘y‘: print(‘GOBY‘) isexit == True break for i1 in shopping: if inp_1 in i1[‘name‘]: money -= i1[‘price‘] if money < 0: while not isexit: print(‘已经透支%s元,请及时充值‘%money) u = input(‘充值金额‘) u1 = int(u) money +=u1 money_2 +=u1 if money >= 0: print(‘您的可用余额%s‘%money) break else: pass m = money_2-money money_3.append(m) print(‘您购买了%s商品,共消费%s元,可用余额%s元,‘%(num,m,money)) shop_car[inp_1] = {‘price‘:i1[‘price‘],‘num‘:num} num += 1
用户登录 import random #验证账号 def Sign_Sign(user_name): f = open(‘D:\E\semantic/py.txt‘,‘r‘,encoding=‘utf-8‘) f.seek(0) for i in f: i1 = i.strip() i2 = i1.partition(‘&‘) if user_name == i2[0]: return True return False #验证密码 def pwd_pwd(user_pwd): f = open(‘D:\E\semantic/py.txt‘,‘r‘,encoding=‘utf-8‘) f.seek(0) for i in f: i1 = i.strip() i2 = i1.partition(‘&‘) if user_pwd == i2[2]: return True return False #添加新密码 def modify_pwd(pwd_modify,pwd_r): f = open(‘D:\E\semantic/py.txt‘,‘r‘,encoding=‘utf-8‘) f.seek(0) list_1 = [] for i in f: i1 = i.strip() i2 = i1.partition(‘&‘) if pwd_modify == i2[0]: name = pwd_modify + ‘&‘ + pwd_r + ‘\n‘ list_1.append(name) continue list_1.append(i) f1 = open(‘D:\E\semantic/py.txt‘,‘a+‘,encoding=‘utf-8‘) f1.seek(0) f1.truncate() for u in list_1: f1.write(u) f1.flush #验证码 def vcation(): while True: vcation_str = ‘‘ for i in range(5): t = random.randrange(0, 9) if t==3 or t==0: y = random.randrange(0,9) u1 = str(y) else: j = random.randrange(65,91) u1 = chr(j) vcation_str += u1 print (vcation_str) vcation_1 = input(‘请输入验证码:‘) vcation_2 = vcation_1.upper() if vcation_2 == vcation_str: return True print(‘验证码错误请重新输入:‘) #主 def Sign(): inp_1 = input(‘欢迎登录淘宝网,登录请按1,注册请按2.修改密码请按3.\n‘) isexit = False #登录 if inp_1 == ‘1‘: while not isexit: user_1 = input(‘请输入登录账号:‘) pwd_1 = input(‘请输入登录密码‘) vcation() r = Sign_Sign(user_1) b = pwd_pwd(pwd_1) if r and b: print(‘登录成功‘) break else: print(‘用户名和密码错误,请重新输入:‘) #注册 elif inp_1 == ‘2‘: while not isexit: user_1 = input(‘请输入注册账号:‘) vcation() r = Sign_Sign(user_1) if r: print(‘账号已经存在‘) continue break pwd_1 = input(‘请输入注册密码‘) name = ‘\n‘ + user_1 + ‘&‘ + pwd_1 f = open(‘D:\E\semantic/py.txt‘,‘a+‘,encoding=‘utf-8‘) f.write(name) f.flush() print(‘恭喜注册成功,请刷新登录‘) Sign() #修改密码 elif inp_1 == ‘3‘: while not isexit: user_1 = input(‘请输入登录账号:‘) pwd_1 = input(‘请输入登录密码‘) vcation() r = Sign_Sign(user_1) b = pwd_pwd(pwd_1) if r and b: while not isexit: pwd_s = input(‘请输入新密码:‘) pwd_r = input(‘再次输入新密码‘) vcation() print(‘恭喜您已经成功修改密码‘) if pwd_r == pwd_s: modify_pwd(user_1,pwd_r) Sign() return else: print(‘两次密码不一致‘) else: print(‘用户名和密码错误,请重新输入:‘) Sign()
以上是关于嵌套 购物车 登录注册的主要内容,如果未能解决你的问题,请参考以下文章