python算账脚本
1.假如小明卡里有10000元去商场买东西发现钱不够又向父母借了5000账单如下
日期(date) | 存钱(save) | 花钱(cost) | 余额(balance) | 描述信息(comment) |
---|---|---|---|---|
20200531 | 0 | 0 | 10000 | int |
20200531 | 0 | 1000 | 9000 | eat |
20200531 | 0 | 3000 | 6000 | buy a computer |
20200531 | 0 | 2000 | 4000 | buy cloth |
20200531 | 0 | 5000 | -1000 | buy a phone |
20200531 | 5000 | 0 | 4000 | borrow |
20200531 | 0 | 1000 | 3000 | play |
2.以下脚本就能实现上面的运算
from time import strftime
import pickle
import os
try:
def save():
data = strftime('\033[35m%Y-%m-%d\033[0m')
money = int(input('How much do you have to save?:'))
comment = input('Which come of money?')
with open('account.book','rb') as fname:
list = pickle.load(fname)
record = list[-1][