设为首页 加入收藏

TOP

Python写的ATM小程序(二)
2014-11-23 20:11:03 来源: 作者: 【 】 浏览:57
Tags:Python ATM 程序
og



withdraw_file_write(n,draw)



return m



def withdraw_file_write(user,withdraw):


shouxufei = cash * 0.05


tran_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))


spath = "record_tran.txt"


f = open(spath,'a')


f.write("%s|%s|withdraw|%d|%d \n" %(user,tran_time,withdraw,shouxufei))


f.close()


cashin.py


#!/usr/bin/python


import time


#cash in function


def cash_in(n,m):


print "Hello %s, your account have %d RMB now." %(n,m)


cash = int(raw_input("Please input how much money you want to save in :"))


m = m + cash


cashin_file_write(n,cash)


return m



def cashin_file_write(user,cashin):


tran_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))


spath = "record_tran.txt"


f = open(spath,'a')


f.write("%s|%s|cashin|%d|0 \n" %(user,tran_time,cashin))


f.close()


printlist.py


#!/usr/bin/python


#select current user's bill


def print_list(n):


print "Hello %s, Here is your bill:" %n


print "Account|Date|Goods|Price|Fee"


spath1 = "./record_tran.txt"


f1 = open(spath1,'r')


for line in f1.readlines():


if line.split('|')[0] == n:


print line


user_list


user1 123


user2 456


goods_list


1 Car 250000


2 Clothes 399


3 Shoes 199


4 Iphone5s 4999


5 Coffee 35


6 Foods 68


7 Bicycle 1688


example of record_tran.txt


user1|2014-07-08 16:59:27|Iphone5s|4999|0


user2|2014-07-08 16:59:31|withdraw|1000|50


user1|2014-07-08 16:59:56|withdraw|500|25


user2|2014-07-09 14:38:33|cashin|3456|0


user2|2014-07-09 14:39:10|Coffee|35|0


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇使用 Meteor 轻松开发实时网站 下一篇Linux线程-sysconf系统变量

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: