Python 信用卡模拟

import time
import linecache

shuaka = 0
quxian = 0
shouxufei = 0

def wlog(log):
        LTIME=time.strftime('%Y-%m-%d %H:%M:%S')
        f=open('d:/xyk.log','a')
        f.write(LTIME+' '+log+'\n')
        f.close()
def zxr():
        linecache.clearcache()
        zonger=str.strip(linecache.getline(r'd:/zonger.txt',1))
        return float(zonger)
def zxx(zonger):
        f=open('d:/zonger.txt','w')
        f.write(zonger)
        f.close()

while True:
    print ('''请选择你要的操作?
            1、刷卡
            2、提现
            3、查询余额
            4、还款
            0、退出
        ''')
    action = float(raw_input())
    if action == 1:
        shuaka=raw_input('请输入刷卡金额:')        
        yuer=zxr()
        while True:
            if float(shuaka)>yuer:
                print("余额不足,请重新输入!")
                break
            else:
                yuer=zxr()- float(shuaka)
                wlog("刷卡金额为:"+str(shuaka)+"元,手续费为:"+str(shouxufei)+"元,余额为:"+str(yuer))
                zxx(str(yuer))
                break      
    elif action == 2:
        quxian=raw_input('请输入取现金额:')
        shouxufei=0.05*float(quxian)
        yuer=zxr()
        while True:
            if float(quxian)+float(shouxufei)>yuer:
                print("余额不足,请重新输入!")
                break
            else:
                yuer = zxr()-float(quxian)-float(shouxufei)
                wlog("取现金额为:"+str(quxian)+"元,手续费为:"+str(shouxufei)+"元,余额为:"+str(yuer))
                zxx(str(yuer))
                break
    elif action == 3:
        yuer = zxr()
        print ('信用卡余额为:'+str(yuer))
        wlog("余额查询,余额为:"+str(yuer))
    elif action == 4:
        huakuan=raw_input("还款金额:")
        yuer = zxr()
        zonger = float(huakuan)+yuer
        zxx(str(zonger))
        yuer = zxr()
        wlog("还款:"+str(huakuan)+"余额为:"+str(yuer))
    elif action == 0:
        break
    else:
        print('你的选择有误,请重新选择')

 

posted on 2016-07-13 10:46  侯志清  阅读(736)  评论(0编辑  收藏  举报

导航