1 import time
2 current_user={'id':None}
3 wenjian=open('db.txt','r+',encoding='utf-8')
4 duqu=eval(wenjian.readline())
5 shijian=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) #定义日志操作时间
6 def log(rizhi):
7 with open('log.txt','a',encoding='utf-8') as l:
8 l.write(rizhi)
9 return rizhi
10 def renzheng(zhanghu):
11 def auth():
12 while True:
13 if current_user['id']:
14 return zhanghu()
15 name_id=input('请输入银行卡ID: ').strip()
16 password=input('请输入密码: ') .strip()
17 if len(password)== 0 and len(name_id) ==0 :
18 print('错误❌')
19 if name_id == duqu['id'] and password == duqu['password'] :
20 print('登录成功')
21 current_user['id']=name_id
22 log('%s 账户[%s]登录成功
' % (shijian, name_id)) #记录登录日志
23 return zhanghu()
24 else:
25 print('登录失败,请检查账户名或密码')
26 log('%s 账户[%s]登录失败
'%(shijian,name_id))
27 return auth
28 @renzheng
29 def chaxun():
30 edu = duqu['money']
31 xiaofei = duqu['shengyu']
32 if xiaofei > edu:
33 huankuan = 0
34 else:
35 huankuan = edu - xiaofei
36 print('''
37 总信用额度:%s
38 剩余可消费:%s
39 本月应还款:%s
40 ''' % (edu, xiaofei, huankuan))
41 time.sleep(3)
42 @renzheng
43 def huankuan():
44 huankuan = input('请输入还款金额:').strip()
45 if huankuan.isdigit():
46 xiaofei = duqu['shengyu']
47 xiaofei += int(huankuan)
48 duqu['shengyu'] = xiaofei
49 print('还款中,请稍后..........')
50 time.sleep(2)
51 print('还款成功,账户可消费金额:%s' % xiaofei)
52 time.sleep(3)
53 wenjian = open('db.txt', 'w', encoding='utf-8')
54 wenjian.write(str(duqu))
55 wenjian.close()
56 @renzheng
57 def gouwuche(): #以前的作业拿来改吧改吧就用上了
58 goods = [
59 {"name": "电脑", "price": 1999},
60 {"name": "鼠标", "price": 10},
61 {"name": "游艇", "price": 20},
62 {"name": "娃娃", "price": 3998},
63 {"name": "气筒", "price": 99},
64 ]
65 kong = []
66 qian = []
67 while True:
68 for k, v in enumerate(goods):
69 print(k, '商品: {name} 价格: {price} RMB'.format(price=v['price'], name=v['name']))
70 sp = input('请输入购买的商品编号[输入j结账][输入r删除购物车商品][输入q退出]: ').strip()
71 if sp == 'q' and len(sp) != 0:
72 break
73 elif sp == 'r':
74 while True:
75 if kong == []:
76 print('======================》没有商品可删了《=====================')
77 break
78 print('您以购买的商品: ')
79 for k, v in enumerate(kong): # for循环显示已购买的商品
80 print(k, '商品: {name} 价格: {price} RMB'.format(price=v[1], name=v[0]))
81 sc = input('请输入删除的商品编号[输入q返回]: ').strip()
82 if sc == 'q' and len(sc) != 0:
83 break
84 if sc.isdigit():
85 if int(sc) < len(kong) and int(sc) >= 0: # 判断输入的数字不能大于列表的下标数字和小于0
86 kong.remove(kong[int(sc)]) # 删除购物车商品
87 else:
88 print('!!!!!!!!!!!!!!!!无效的输入!!!!!!!!!!!!!!!!!!!')
89 else:
90 print('