#encoding=utf-8
import pickle
income = []
spend = []
deposit = 0.0
while 1:
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:
spend.append(abs(amount))
deposit -= amount
else:
print("余额不足!")
print("收入:",income)
print("支出:",spend)
print("余额:",deposit)
file_obj = open("e:\\in_out.txt","wb")
pickle.dump(income,file_obj)
pickle.dump(spend,file_obj)
pickle.dump(spend,file_obj)
file_obj.close()