标签:huawei app comm 失败 strip() 余额 write while 数字
d = {}
with open(‘b.txt‘, mode=‘rt‘, encoding=‘utf-8‘) as f:
res = f.readlines()
for line in res:
i = line.strip(‘\n‘).split(‘:‘)
d[i[0]] = i[1]
while True:
inp_user = input(‘inp_user>>>:‘).strip()
if inp_user not in d:
print(‘对不起用户名不存在,请重新输入‘)
continue
else:
inp_pwd = input(‘inp_pwd>>>:‘).strip()
if d[inp_user] == inp_pwd:
print(‘登录正确‘)
# item = inp_user
d1 = {}
with open(‘a.txt‘, mode=‘rt‘, encoding=‘utf-8‘) as f:
res = f.readlines()
for line in res:
i = (line.strip(‘\n‘)).split(‘:‘)
d1[i[0]] = i[1]
# print(d1)
item = d1[inp_user]
# print(item) # 金额
while True:
print(‘您好您的余额还有‘, item)
print(‘请问您是否充值?(y/n)‘)
commend = input(‘commend>>>:‘)
if commend == ‘y‘:
money1 = input(‘请输入充值金额>>>:‘)
# 这个可以加一个只能输入纯数字
# 输入错误,请重新输入
# print(‘进入充值界面‘)
money = int(money1) + int(item)
line2 = ‘%s:%s\n‘ % (inp_user, money)
# 这个后面可以跟一个追加日志某某什么时间扣款多少元
with open(‘a.txt‘, mode=‘at‘, encoding=‘utf-8‘) as f1:
f1.write(line2)
item = money
elif commend == ‘n‘:
# while True:
print(‘欢迎光临本店,便宜不贵,经济实惠‘)
# 浏览信息界面
print(‘iphone12 ¥2000‘)
print(‘如果购买iphone12请输入a‘)
print(‘1斤苹果 ¥8‘)
print(‘如果购买1斤苹果请输入b‘)
print(‘华为p40, 4999¥‘)
print(‘如果购买华为p40请输入c‘)
while True:
buy = input(‘buy>>>:‘)
if buy == ‘a‘:
if int(item) > int(d1[‘iphone‘]):
print(‘恭喜你购买成功‘)
res = int(item) - int(d1[‘iphone‘])
print(‘你余额还有‘, res)
line3 = ‘%s:%s\n‘ % (inp_user, res)
# 这个后面可以跟一个追加日志某某什么时间扣款多少元
with open(‘a.txt‘, mode=‘at‘, encoding=‘utf-8‘) as f1:
f1.write(line3)
item = res
else:
print(‘购买失败,对不起您的余额已不足请充值‘)
agree = input(‘agree>>>:‘)
if agree == ‘yes‘:
money1 = input(‘请输入充值金额>>>:‘)
# 这个可以加一个只能输入纯数字
# print(‘进入充值界面‘)
money = int(money1) + int(item)
line2 = ‘%s:%s\n‘ % (inp_user, money)
# 这个后面可以跟一个追加日志某某什么时间扣款多少元
with open(‘a.txt‘, mode=‘at‘, encoding=‘utf-8‘) as f1:
f1.write(line2)
print(‘充值成功,您继续购买‘)
continue
else:
break
elif buy == ‘b‘:
if int(item) > int(d1[‘a_catty_of_appeles‘]):
print(‘恭喜你购买成功‘)
res = int(item) - int(d1[‘a_catty_of_appeles‘])
print(‘你余额还有‘, res)
line4 = ‘%s:%s\n‘ % (inp_user, res)
# 这个后面可以跟一个追加日志某某什么时间扣款多少元
with open(‘a.txt‘, mode=‘at‘, encoding=‘utf-8‘) as f1:
f1.write(line4)
item = res
else:
print(‘购买失败,对不起您的余额已不足请充值‘)
agree = input(‘agree>>>:‘)
if agree == ‘yes‘:
money1 = input(‘请输入充值金额>>>:‘)
# 这个可以加一个只能输入纯数字
# print(‘进入充值界面‘)
money = int(money1) + int(item)
line2 = ‘%s:%s\n‘ % (inp_user, money)
# 这个后面可以跟一个追加日志某某什么时间扣款多少元
with open(‘a.txt‘, mode=‘at‘, encoding=‘utf-8‘) as f1:
f1.write(line2)
print(‘充值成功,您继续购买‘)
continue
else:
break
elif buy == ‘c‘:
if int(item) > int(d1[‘huawei_p40‘]):
print(‘恭喜你购买成功‘)
res = int(item) - int(d1[‘huawei_p40‘])
print(‘你余额还有‘, res)
line5 = ‘%s:%s\n‘ % (inp_user, res)
# 这个后面可以跟一个追加日志某某什么时间扣款多少元
with open(‘a.txt‘, mode=‘at‘, encoding=‘utf-8‘) as f1:
f1.write(line5)
item = res
else:
print(‘购买失败,对不起您的余额已不足请充值‘)
agree = input(‘agree>>>:‘)
if agree == ‘yes‘:
money1 = input(‘请输入充值金额>>>:‘)
# 这个可以加一个只能输入纯数字
# print(‘进入充值界面‘)
money = int(money1) + int(item)
line2 = ‘%s:%s\n‘ % (inp_user, money)
# 这个后面可以跟一个追加日志某某什么时间扣款多少元
with open(‘a.txt‘, mode=‘at‘, encoding=‘utf-8‘) as f1:
f1.write(line2)
print(‘充值成功,您继续购买‘)
continue
else:
break
else:
print(‘对不起用户名或者密码输入错误‘)
continue
标签:huawei app comm 失败 strip() 余额 write while 数字
原文地址:https://www.cnblogs.com/yanglong180/p/14883271.html