atm(选做)——实现信用卡程序 python

atm(选做)——实现信用卡程序
基础需求:
信用卡为用户提供功能:
    查询余额
    查询账单
    提现取款  提现手续费5% 额度 10000或自定义
    转账
    查看本月消费 消费和日常操作等内容以字符串的形式记录到文件中

    *以上所有功能均需做用户认证,请用装饰器完成



注意  :#登录账号信息


user={"egon":"111","alex":"222","wusir":"333","somebody":"444"}


运行方式:

信用卡程序功能
	cb   -----查询余额
	dm   -----提现取款
	ta   -----转账
	cc   -----查看本月消费
	exit -----退出

Please enter the command above:cb
===>user_name:egon
===>user_password:111
login  successful
check_balance==>当前余额为:0
查询余额操作完成!


Please enter the command above:dm
darw_money==>当前余额为:0  限超出额度:10000  手续费率:0.05
Please enter the amount of money you withdraw:5000
------扣除手续费:250.0   取款余额:5000   剩余余额(已扣手续费):-5250.0
取款操作完成!

Please enter the command above:ta
transfer_accounts==>当前余额为:-5250.0
Please enter the name of the transfer person:luo
enter  car number:123779909003331133
enter transfer money:5000
-----转账对象 姓名=luo   卡号=123779909003331133   转钱数=5000   剩余余额=-10250.0
转账完成!

Please enter the command above:cc
执行操作: login==>name=egon   password=12312414-----login failed   please enter again
执行操作: login==>name=egon   password=111-----login  successful
执行操作: check_balance==>当前余额为:0
执行操作: darw_money==>当前余额为:0  限超出额度:10000  手续费率:0.05------扣除手续费:200.0   取款余额:4000   剩余余额(已扣手续费):-4200.0
执行操作: darw_money==>当前余额为:-4200.0  限超出额度:10000  手续费率:0.05------超出限额 , 取款失败!
执行操作: darw_money==>当前余额为:-4200.0  限超出额度:10000  手续费率:0.05------扣除手续费:250.0   取款余额:5000   剩余余额(已扣手续费):-9450.0
执行操作: transfer_accounts==>当前余额为:-9450.0-----转账对象 姓名=luo   卡号=123321123312   转钱数=500   剩余余额=-9950.0
执行操作: login==>name=egon   password=111-----login  successful
执行操作: check_balance==>当前余额为:0
执行操作: login==>name=egon   password=111-----login  successful
执行操作: check_balance==>当前余额为:0
执行操作: login==>name=egon   password=111-----login  successful
执行操作: login==>name=egon   password=111-----login  successful
执行操作: check_balance==>当前余额为:0
执行操作: darw_money==>当前余额为:0  限超出额度:10000  手续费率:0.05------扣除手续费:250.0   取款余额:5000   剩余余额(已扣手续费):-5250.0
执行操作: login==>name=egon   password=111-----login  successful
执行操作: transfer_accounts==>当前余额为:0-----转账对象 姓名=ta   卡号=luo   转钱数=1431234118800331   剩余余额=-1431234118800331
执行操作: login==>name=egon   password=111-----login  successful
执行操作: transfer_accounts==>当前余额为:0-----转账对象 姓名=luo   卡号=12345723488000113   转钱数=5000   剩余余额=-5000
执行操作: login==>name=egon   password=111-----login  successful
执行操作: check_balance==>当前余额为:0
执行操作: darw_money==>当前余额为:0  限超出额度:10000  手续费率:0.05------扣除手续费:250.0   取款余额:5000   剩余余额(已扣手续费):-5250.0
执行操作: transfer_accounts==>当前余额为:-5250.0-----转账对象 姓名=luo   卡号=123779909003331133   转钱数=5000   剩余余额=-10250.0
查看本月消费完成!


----------------------------------------------------------代码------------------------------------------------

#余额
balance ={"money":0}
#登录状态
state={"state":False}
#log日志
def w_log(operation):
    with open("consume_log.txt","a",encoding="utf-8") as f:
        f.write("执行操作: "+operation+"\n")


#登录账号信息
user={"egon":"111","alex":"222","wusir":"333","somebody":"444"}
# 登录验证
def login():
    name =input("===>user_name:").strip()
    passwd = input("===>user_password:").strip()
    str = "login==>name={}   password={}-----".format(name,passwd)
    if name in user and passwd == user[name]:
        str1 = "login  successful"
        state["state"]=True
        print(str1)
    else:
        str1="login failed   please enter again"
        print(str1)
    str = str + str1
    w_log(str)


#装饰器
def wrapper(func):
    def inner(*args,**kwargs):
        while not state["state"]:
            login()
        ret = func(*args,**kwargs)
        return ret
    return inner


#查询余额
@wrapper
def check_balance():
    str = "check_balance==>当前余额为:{}".format(balance["money"])
    print(str)
    print("查询余额操作完成!\n")
    w_log(str)#操作写入日志


#提现取款  提现手续费5% 额度 10000或自定义
@wrapper
def draw_money(poundage=0.05,quota=10000):
    str="darw_money==>当前余额为:{}  限超出额度:{}  手续费率:{}".format(balance["money"],quota,poundage)
    print(str)
    money= int(input("Please enter the amount of money you withdraw:").strip())
    if balance["money"] -money >= -quota:
        balance["money"] = balance["money"] - money -money*poundage     #扣除取款 扣除手续费
        str1="------扣除手续费:{}   取款余额:{}   剩余余额(已扣手续费):{}".format(money*poundage,money,balance["money"])
        str=str+str1
    else:
        str1="------超出限额 , 取款失败!"
        str = str+str1


    print(str1)
    print("取款操作完成!\n")
    w_log(str)


#转账
@wrapper
def transfer_accounts():
    str = "transfer_accounts==>当前余额为:{}".format(balance["money"])
    print(str)
    #输入转账对象信息
    name=input("Please enter the name of the transfer person:").strip()
    car_number=input("enter  car number:").strip()
    t_money=int(input("enter transfer money:").strip())
    balance["money"]-=t_money
    str1 = "-----转账对象 姓名={}   卡号={}   转钱数={}   剩余余额={}".format(name,car_number,t_money,balance["money"])
    str = str +str1


    print(str1)
    print("转账完成!\n")
    w_log(str)


#查看本月消费 消费和日常操作等内容以字符串的形式记录到文件中
@wrapper
def check_consume(filename="consume_log.txt"):
    with open(filename,encoding="utf-8") as f:
        for x in f:
            print(x,end="")
    print("查看本月消费完成!\n")


#命令界面
info ='''\t\t信用卡程序功能
\tcb   -----查询余额
\tdm   -----提现取款
\tta   -----转账
\tcc   -----查看本月消费
\texit -----退出
'''


#被装饰后的函数字典
func_dict={"cb":check_balance,"dm":draw_money,"ta":transfer_accounts,"cc":check_consume,"exit":exit}


while True:
    print(info)
    cmd =input("Please enter the command above:").strip()
    if cmd in func_dict:
        func_dict[cmd]()
    else:
        print("error,error---please enter again")



----------------------------------------------------------代码--------------------------------------------




  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值