设为首页 收藏本站
查看: 1150|回复: 0

[经验分享] 通过python实现信用卡消费机制

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-15 10:22:16 | 显示全部楼层 |阅读模式
功能要求:
1.额度15000
2.可以体现,手续费是5%
3每月最后一天是出账单,写入一个文件
4.记录每月日常消费流水(每天的没笔消费)
5.写出来本期还款

python源代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# encoding=utf-8
# author:sihaogongyuan
# date:2015-4-13
# filename:atm-py
# desc:atm-py
#################################################
import sys
import os
sys.path.append('/tmp/python/')
import tab
import time
#################################################
credit_line=int(15000)
old_money=int(15000)
#print type(credit_line)
#counter_fee=0.05
fee_rate=0.05
#################################################
#date=time.strftime('%Y-%m-%d %H:%M:%S')
#################################################
date1=time.strftime('%Y-%m-%d-%H:%M:%S')
f=file('%s.log'%(date1),'w')
f.close()
f=file('%s.log'%(date1),'a')
f.write('交易日期\t交易摘要\t金额\t手续费\t信用额度\n')
#######取现######################################
def qu_xian():
  global credit_line
  global fee_rate
#date=os.system("date '+%F:%T'")
#print date
date=time.strftime('%Y-%m-%d %H:%M:%S')
quxian_money=int(raw_input('请输入取现金额:').strip())
#print quxian_money,type(quxian_money)
while quxian_money=='':
    continue
  #print quxian_money,type(quxian_money)
if 0<quxian_money<=credit_line:
  #定义手续费counter_fee
  counter_fee=quxian_money*fee_rate
  credit_line=credit_line-quxian_money-counter_fee
  print '\033[32m已取%d元,手续费是%d元,信用额度是%d元\033[0m'%(quxian_money,counter_fee,credit_line)
  f.write('%s\t取现\t%s\t%d\t%d\n'%(date,quxian_money,counter_fee,credit_line))
  f.flush()
else:
  print '\033[31m取现金额%d不在信用额度内,取现失败\033[0m'%(quxian_money)
#######刷卡########################################
def shua_ka():
global credit_line
#date=os.system("date '+%F:%T'")
date=time.strftime('%Y-%m-%d %H:%M:%S')
shuaka_money=int(raw_input('请输入消费金额:').strip())
if 0<shuaka_money<=credit_line:
  credit_line=credit_line-shuaka_money
  print '\033[32m已消费%d元,信用额度是%d元\033[0m'%(shuaka_money,credit_line)
  #f.write(os.system('date'),'\t','刷卡','\t',shuaka_money,0)
  f.write('%s\t刷卡\t%s\t0\t%d\n'%(date,shuaka_money,credit_line))
  f.flush()
else:
  print '\033[31m消费金额%d不在信用额度内,消费失败\033[0m'%(shuaka_money)
########存钱#######################################
def cun_qian():
global credit_line
#date=os.system("date '+%F:%T'")
date=time.strftime('%Y-%m-%d %H:%M:%S')
cun_qian_money=int(raw_input('请输入存钱金额:').strip())
if cun_qian_money>0:
  credit_line=credit_line+cun_qian_money
  print '\033[32m存款%d成功,目前信用额度是:%d'%(cun_qian_money,credit_line)
  f.write('%s\t存钱\t-%s\t0\t%d\n'%(date,cun_qian_money,credit_line))
  f.flush()
else:
  print '\033[31m存取金额%d不符合规范,存款失败\033[0m'%(cun_qian_money)
###########main####################################
print '\t欢迎来到ATM系统'
while True:
#credit_line=int(15000)
#fee_rate=0.05
choice=raw_input('请输入你要进行的操作(取现,消费,存钱,退出):').strip()
if choice=='':
    continue
if choice=='取现' or choice=='提现':
  qu_xian()
  continue
elif choice=='刷卡' or choice=='消费':
  shua_ka()
  continue
elif choice=='存钱' or choice=='存款':
  cun_qian()
  continue
elif choice=='退出' or choice=='exit':
  break
else:
  print '不合规的操作,请重新选择'
  continue
###################################################
f.write('\033[32m目前可用信用额度为:%s\n\033[0m'%(credit_line))
f.flush()
f.write('\033[32m本期还款金额为%d\n\033[0m'%(old_money-credit_line))
f.flush()
f.close()
f=file('%s.log'%(date1),'r')
print f.read()
###################################################



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-57378-1-1.html 上篇帖子: 实现批量添加20个用户,用户名为user1-20,密码为user后面跟5 个随机字符 下篇帖子: Python字符串处理函数 信用卡 python
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表