python Accounting script

1. If xiaomingkari has 10000 Yuan went to the shopping mall and found that he didn't have enough money and borrowed it from his parents 5000 The bill is as follows

date (date) save money (save) Spending money (cost) balance (balance) Description information (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. The following script can implement the above operation
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('','rb')
as fname: list = pickle.load(fname) record = list[-1][-2] balance = record +
moneylist.append([data,money,0,balance,comment]) with open('','wb')
as fname: pickle.dump(list,fname) def cost(): data = strftime(
'\033[35m%Y-%m-%d\033[0m') money = int(input('How much did you spend?:'))
comment= input('Where is it used?:') with open('','rb') as fname:
list = pickle.load(fname) record = list[-1][-2] balance = record - money list.
append([data,0,money,balance,comment]) with open('', 'wb') as fname:
pickle.dump(list, fname) def query(): print(
'\033[34m%-20s%-9s%-9s%-10s%-18s\033[0m' % ('date','save','cost','balance',
'comment')) with open('','rb') as fname: record = pickle.load(fname)
for i in record: print('%-29s%-9s%-9s%-10s%-20s' % tuple(i)) def choice_memu():
promat=''' (0)save (1)cost (2)query (3)exit please choice:''' fname =
'' if not os.path.exists(fname): with open(fname,'wb') as obj: t_t =
strftime('\033[35m%Y-%m-%d\033[0m') data = [[t_t,0,0,10000,'int']] pickle.dump(
data,obj) while 1: cmds = {'0':save,'1':cost,'2':query} choice = input(promat)
if choice not in ['0','1','2','3']: continue if choice == '3': print(
'\033[32msee you\033[0m') break cmds[choice]() if __name__ == '__main__':
choice_memu() except KeyboardInterrupt: print('\033[32msee you\033[0m') except
ValueError: print('\033[31minvalid inputs\033[0m')
3. Compared with the above table, the result is the same

©2019-2020 Toolsou All rights reserved,
Final review of database : Summary of comprehensive application questions use Python Make simple games Laplance operator ( Second derivative ) Convert hard disk to GPT Partition format Python Implementation of Hanoi Tower code about String How to create objects vue3 Learning journey 1—— establish vue3 project java String from back to front _Java String String summary use Python Write a story about plants versus zombies 【 Greedy Algorithm 】 Huffman coding problem