登陆注册的购物车 2018.09.25

def login():
while True:
d = {}
with open(r'aa.txt',mode='rt',encoding='utf_8') as uname:
user=uname.read().split('|')
for t in user:
k,v = t.split(':')
d[k] = v
name = input('用户名: ').strip()
if name not in d:
print('用户不存在')
continue
else:
with open(r'db.txt',mode='rt',encoding='utf_8') as f:
lock_1=f.read().split('|')
if name in lock_1:
print('用户%s已经被锁定' %name)
continue
x = 0
tag=True
while tag:
sky = input('输入密码:').strip()
if sky == d[name]:
print('登陆成功!')
x = 0
return recharge(name)
elif x == 2:
print('用户锁定,请找回密码')
with open('db.txt', 'a') as p:
p.write('%s|' % name)
continue
else:
print('密码错误,请重新输入')
x += 1
def regis():
while True:
d = {}
with open(r'aa.txt', mode='rt', encoding='utf_8') as uname:
user = uname.read().split('|')
for t in user:
k, v = t.split(':')
d[k] = v
name_1 = input('注册用户名: ').strip()
if name_1[0].isdigit():
continue
if name_1 in d:
print('用户名已经存在')
continue
else:
while True:
key = input('输入密码').strip()
if '*' in key:
continue
if'$'in key:
continue
if '&'in key:
continue
elif len(key)>5:
with open(r'aa.txt', mode='at',encoding='utf_8')as ff:
ff.write('|%s:%s' %(name_1,key))
print('注册成功,请重新登陆!')
return login()


def recharge(name):
d = {}
while True:
with open(r'bb.txt', mode='rt', encoding='utf_8') as uname:
user = uname.read()
for t in user.split('|'):
k, v = t.split(':')
d[k] = v
print(name,d[name])
summon=int(d[name])
ise = input('退出 1继续2')
if ise == '1':
return
rec=input('是否进行充值1,2').strip()
if rec=='1':
money=int(input('充值金额').strip())
summon=money+summon
with open(r'bb.txt', mode='wt', encoding='utf_8') as uname:
uname.write(user.replace('%s:%s'%(name,d[name]),'%s:%s'%(name,summon)))
next_1=input('充值成功,当前余额%s;是否继续充值1,2?'%summon)
if next_1=='2':
ise = input('退出 1继续2')
if ise == '1':
return
else:
return shopping(name,summon)
elif next_1=='1':
continue
else:
return shopping(name,summon)


def shopping(name,summon):
msg_dic={
'apple':10,
'tesla':100000,
'mac':3000,
'lenovo':30000,
'chicken':10,
}
goods_l={}
amount=0
for key,item in msg_dic.items():
print('name:{name} price:{price}'.format(price=item,name=key))
while True:
choice=input('商品>>: ').strip()
if choice not in msg_dic:
continue
count=input('购买数量>>: ').strip()
if choice not in msg_dic:
continue
else:
goods_l[choice] = [msg_dic[choice], count]
amount=amount+int(msg_dic[choice])*int(count)
print(goods_l,'小计%s'%amount)
settle = input('是否结算1,2')
if settle=='2':
continue
elif int(summon)>amount and settle=='1':
with open(r'bb.txt',mode='rt',encoding='utf_8')as uname:
user=uname.read()
with open(r'bb.txt', mode='wt', encoding='utf_8')as uname:
uname.write(user.replace('%s:%s' % (name, summon), '%s:%s' % (name, int(summon)-amount)))
print('支付成功,当前余额%s'%(int(summon)-amount))
ise = input('是继续购物1或退出 2')
if ise == '1':
summon =str(int(summon) - amount)
return shopping(name,summon)
else:
return
else:
recharge('name')

login()

猜你喜欢

转载自www.cnblogs.com/yanhui1995/p/9702670.html