- 帖子
- 31
- 精华
- 0
- 积分
- 111
- 阅读权限
- 20
- 注册时间
- 2021-2-8
- 最后登录
- 2021-4-13
|
希望老师评价一下,欢迎各种建议- from datetime import date
- from re import findall
- def keep_ac():
- global ac_cont
- amount = input('请输入收支情况(类似于+100,-50)\n')
- things = input('请输入收支名目\n')
- while True:
- print('请问此次收支的时间是今天吗?')
- input_w = '如果是,请按回车;'
- input_w += '如果不是,请输入时间(类似于2000-01-01)\n'
- time = input(input_w)
- break
- if time == '':
- time = date.today()
- add_w = '{} {} {}'.format(time,amount,things)
- balance = int((findall(r'-?\d+',ac_cont[-1]))[0])
- balance_sen = '余额:' + str(balance + int(amount)) + '元'
- del ac_cont[-1]
- ac_cont.append(add_w)
- ac_cont.append('\n'+balance_sen)
- ac_wri = open('C:\\Users\\ac_book.txt','w',encoding = 'utf-8')
- ac_wri.writelines(ac_cont)
- ac_wri.close()
- def ff_bala():
- balance = ac_cont[-1]
- print(balance)
- def detail():
- de = ac_cont[:-1]
- for d in de:
- print(d,end = '')
- print()
- print('本记账本有以下三种功能供您使用:')
- print('1.记账 2.查余额 3.查看收支明细')
- while True:
- global ac_cont
- ac_book = open('C:\\Users\\ac_book.txt',encoding = 'utf-8')
- ac_cont = ac_book.readlines()
- ac_book.close()
- function = input('\n请输入数字(1~3)以使用对应功能,要退出时请按回车:\n')
- if function == '1':
- keep_ac()
- elif function == '2':
- ff_bala()
- elif function == '3':
- detail()
- elif function == '':
- break
- else:
- print('输入无效哦!')
复制代码 |
|