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