2019-05-21: write a bookkeeping program, how much revenue a day, how much spending, how much of the total left, use serialization to save the information

#encoding=utf-8
import pickle

income = []
spent=[]
deposit = 0.0

while True:
    command = input("请输入收入、支出、总额,例如收入|50,输入q退出:")
    if command.lower()=="q":
        break
    try:
        amount = float(command.split("|")[1])
    except Exception as e:
        print("输入错误请重新输入")
        continue
    else:
        type = command.split("|")[0]
        if type =="收入":
            income.append(amount)
            deposit += amount
        elif type =="支出":
            if deposit - abs(amount)>=0:
                spent.append((abs(amount)))
                deposit-=amount
            else:
                print("余额不足")
print("收入:",income)
print("支出",spent)
print("余额",deposit)
fp = open("e:\\murphy\\data\\in_out.txt","wb")
pickle.dump(income,fp)
pickle.dump(spent,fp)
pickle.dump(deposit,fp)
fp.close()

 

Guess you like

Origin blog.csdn.net/sinat_18722099/article/details/90399348