python之记账程序_Python实现简单的记账本功能

  • Post author:
  • Post category:python


#!/usr/bin/env python#coding:utf8

importos,sysimporttime”’1.运行该脚本会生成一个balance.txt文件,并设置初始账户余额:¥10000

2.运行该脚本会生成一个account.txt文件,并记录账户消费信息详情。”’

defsave():

date= time.strftime(“%Y-%m-%d”)

cost=0while 1:try:

save= int(raw_input(“请输入存款金额:”).strip())exceptValueError:print “\033[31m请输入数值类型,重新输入!\033[0m”

continue

except(KeyboardInterrupt,EOFError):

sys.exit(“\n\033[31m程序退出\033[0m”)if save <=0:print “\033[31m请输入一个大于0的存款金额:\033[0m”

continue

while 1:try:

comment= str(raw_input(“请输入存款信息:”))except(KeyboardInterrupt,EOFError):

sys.exit(“\n\033[31m程序退出\033[0m”)if notcomment:continue

break

breakbalance=rekcon_balance(save,cost)

a.write(‘%-12s%-12s%-12s%-12s%-12s\n’ %(date, cost, save, balance, comment))

<