作业需求:
模拟实现一个ATM + 购物商城程序
- 额度 15000或自定义
- 实现购物商城,买东西加入 购物车,调用信用卡接口结账
- 可以提现,手续费5%
- 每月22号出账单,每月10号为还款日,过期未还,按欠款总额 万分之5 每日计息
- 支持多账户登录
- 支持账户间转账
- 记录每月日常消费流水
- 提供还款接口
- ATM记录操作日志
- 提供管理接口,包括添加账户、用户额度,冻结账户等。。。
- 用户认证用装饰器
1、额度15000或自定义功能。
# Author: ray.zhang
import sys
while True:
user = str(input(" 33[1;32;40mPlease input your name: 33[0m"))
f = open('user_list', 'r+')
for line in f.readlines():
n = str(line.split()[0])
p = str(line.split()[1])
if user == n:
while True:
password = str(input(" 33[1;32;40mPlease input your password: 33[0m"))
if password != p:
print
" 33[1;31;40mThe password is incorrect 33[0m"
continue
else:
print
" 33[1;32;40myes let you in. 33[0m"
global money
money_total = 15000
print(" 33[1;33;40mYou total money is: 33[0m", money_total)
exit()
else:
print
" 33[1;31;40mThe user is not vaild, please re-input: 33[0m"
continue
2、支持多账户登录
# Author: ray.zhang
dict = {
'user1':{'pass':123,'count':0},
'user2':{'pass':456,'count':0},
'user3':{'pass':789,'count':0}
}
name = input ("plz input your name: ")
print (dict[name]['pass'])
if name not in dict:
print ("Sorry,you input error.")
exit()
elif name in dict :
print ("Ok,you input success.")
while dict[name]['count'] < 3:
pas = int(input("plz input your passwd: "))
if pas == dict[name]['pass']:
print ("Congratulation to you.")
dict[name]['count'] = 3
else:
dict[name]['count'] += 1
3、实现用户认证装饰器
# Author: ray.zhang
import time
user_dict={'user':None}
def auth(func):
def wrapper():
print(user_dict['user'])
#user = user_dict['user']
#print(user_dict['user'])
if user_dict['user']:
starttime = time.time()
func()
stoptime = time.time()
print("Run time is %s" % (stoptime - starttime))
if not user_dict['user']:
user = input("plz input your user:").strip()
passwd = int(input("plz input your passwd:").strip())
with open('info','r',encoding='utf-8') as f:
date=eval(f.read())
starttime = time.time()
if user in date and passwd == date[user]:
# if user == "erav" and passwd == 123:
print("you input success...")
func()
stoptime = time.time()
print("Run time is %s" %(stoptime - starttime))
user_dict['user'] = user
else:
print("you input error...")
return wrapper
@auth #这个就相当于 timmer=auth(timmer)
def timmer():
time.sleep(2)
print("welcome to shopping")
timmer()