码迷,mamicode.com
首页 > 其他好文 > 详细

ATM类形式

时间:2018-11-27 22:16:06      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:fun   余额   tm机   dict   elf   bre   open   format   rom   

information.py
dic={}
def load():
    f=open(‘dict.txt‘,‘w‘)
    f.writelines(str(dic))
    f.close

def read():
    f=open(‘dict.txt‘)
    global dic
    dic=eval(f.read())
    f.close()
    return dic

def bill():
    global dic
    for account in dic:
        dic[account][‘流水‘]={}
    z=open(‘账单.txt‘,‘w‘)
    z.writelines(str(account)+‘账单:‘+str(dic[account][‘流水‘]))       
    z.close()

dic=read()

  

credit_card.py

import information as i
import time

dic=i.read()

class card():
    def __init__(self):#注册
        global dic
        while True:
            account=input("请输入您的新账号:")
            if account in dic:
                print("您的账号已被注册,请重新输入:")
            else:
                break
        password=input("请输入您的新密码:")
        dic[account]={‘密码‘:password,‘余额‘:0.0,‘信用额度‘:15000,‘已使用额度‘:0.0,‘流水‘:{}}
        i.load()
        print(‘恭喜您建立新账户!‘)

    def login():#登录
        global dic,account
        while True:
            account=input("请输入您的账号:")
            password=input("请输入您的密码:")
            if account not in dic:
                print(‘您的账号不存在,请先注册!‘)
                __init__()
            elif password!=dic[account][‘密码‘]:
                print("账号与密码不匹配,请重新输入:")
            else:
                print(‘您已登陆成功!‘)
                break
        return account
    
    def balance(account):#查询余额
        global dic
        print("您的余额为",dic[account][‘余额‘],‘信用额度为‘,dic[account][‘信用额度‘],‘已用额度为‘,dic[account][‘已使用额度‘])


    def withdraw(account):#取款
        global dic
        number=float(input(‘请输入取款金额:‘))
        if number<=dic[account]["余额"]:
            dic[account]["余额"]=dic[account]["余额"]-number
            print("取款成功!")
            dic[account][‘流水‘][time.ctime()]="  "+str(number)+"  "+"取款"+"  "+str(dic[account][‘余额‘])+"  "+str(dic[account][‘已使用额度‘])
        elif number+(number-dic[account]["余额"])*0.05<=dic[account]["余额"]+dic[account][‘信用额度‘]-dic[account][‘已使用额度‘]:
            dic[account][‘已使用额度‘]=dic[account][‘已使用额度‘]+(number-(number-dic[account]["余额"]))*1.05
            dic[account]["余额"]=0.0
            print("取款成功!")
            dic[account][‘流水‘][time.ctime()]="  "+str(number)+"  "+"取款"+"  "+str(dic[account][‘余额‘])+"  "+str(dic[account][‘已使用额度‘])
        else:
            print("余额不足!")
        i.load()

    def save(account):#存款
        global dic
        number=float(input(‘存款金额:‘))
        dic[account]["余额"]=dic[account]["余额"]+number
        print("存款成功!")
        dic[account][‘流水‘][time.ctime()]="  "+str(number)+"  "+"存款"+"  "+str(dic[account][‘余额‘])+"  "+str(dic[account][‘已使用额度‘])
        i.load()

    def creditcard(account):#刷卡
        global dic
        number=float(input(‘待付款金额:‘))
        while True:
            password=input("请输入你的密码")
            if password!=dict[account][‘密码‘]:
                    print("账号与密码不匹配,请重新输入:")
            else:
                break
        if number<=dic[account]["余额"]:
            dic[account]["余额"]=dic[account]["余额"]-number
            print("刷卡成功!")
            dic[account][‘流水‘][time.ctime()]="  "+str(number)+"  "+"刷卡"+"  "+str(dic[account][‘余额‘])+"  "+str(dic[account][‘已使用额度‘])
            i.load()
        elif number+(number-dic[account]["余额"])*0.05<=dic[account]["余额"]+dic[account][‘信用额度‘]-dic[account][‘已使用额度‘]:
            dic[account][‘已使用额度‘]=dic[account][‘已使用额度‘]+number-(number-dic[account]["余额"])*0.05
            print("刷卡成功!")
            dic[account][‘流水‘][time.ctime()]="  "+str(number)+"  "+"刷卡"+"  "+str(dic[account][‘余额‘])+"  "+str(dic[account][‘已使用额度‘])
            dic[account]["余额"]=0.0
            i.load()
        else:
            print("余额不足!")
        
        

    def repay(account):#还款
        global dic
        number=float(input(‘还款金额:‘))
        if number<=dic[account]["已使用额度"]:
            dic[account]["已使用额度"]=dic[account]["已使用额度"]-number
            print("还款成功")
            dic[account][‘流水‘][time.ctime()]="  "+str(number)+"  "+"还款"+"  "+str(dic[account][‘余额‘])+"  "+str(dic[account][‘已使用额度‘])
            i.load()
        else:
            over=number-dic[account]["已使用额度"]
            dic[account]["余额"]=dic[account]["余额"]+number-dic[account]["已使用额度"]
            dic[account][‘流水‘][time.ctime()]="  "+str(dic[account]["已使用额度"])+"  "+"取款"+"  "+str(dic[account][‘余额‘])+"  "+str(dic[account][‘已使用额度‘])
            dic[account]["已使用额度"]=0.0
            print(‘无未还记录,多余金额已转存入账户余额‘)
            dic[account][‘流水‘][time.ctime()]="  "+str(over)+"  "+"存款"+"  "+str(dic[account][‘余额‘])+"  "+str(dic[account][‘已使用额度‘])
            i.load()

    def interest(account):#计息
        if time.localtime().tm_mday==10:
            global dic
            for acoount in dic:
                if dic[account]["余额"]>=dic[account][‘已使用额度‘]*0.05:
                    dic[account]["余额"]=dic[account]["余额"]-dic[account][‘已使用额度‘]*0.05
                else:
                    dic[account][‘已使用额度‘]=dic[account][‘已使用额度‘]-dic[account][‘已使用额度‘]*0.05+dic[account]["余额"]
        i.load()

    

  

ATM_main.py

from credit_card import card

def atmfunc(account):
    while True:
        print(‘‘‘欢迎使用ATM终端机:
    1.查询
    2.取款
    3.存款
    4.还款
    5.退卡‘‘‘)
        choice=input(‘请选择您需要的功能:‘)
        if choice==‘1‘:
            card.balance(account)
            
        elif choice==‘2‘:
            card.withdraw(account)
            
        elif choice==‘3‘:
            card.save(account)
            
        elif choice==‘4‘:
            card.repay(account)
           
        elif choice==‘5‘:
            print(‘您已退出登陆!\n感谢使用!请保管好您的信用卡!‘)
            lor()
            break
        else:
            print(‘无效输入!‘)
            
def lor():
    while True:
        start=input(‘您好!欢迎使用ATM机!\n若您未注册,请输入1注册,若有账号,请输入2登陆:‘)
        if start==‘1‘:
            p=card()
            atmfunc(card.login())
        elif start==‘2‘:
            atmfunc(card.login())
        else:
            print(‘无效输入!‘)
            continue
def main():
    while True:
        lor()#注册或登录


if __name__==‘__main__‘:
    main()

  

ATM类形式

标签:fun   余额   tm机   dict   elf   bre   open   format   rom   

原文地址:https://www.cnblogs.com/dongyao-cufe/p/10029058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!