python实现日常记账本小程序

发布时间:2024-12-21 20:22

获取Python程序员的Python证书 #生活技巧# #学习技巧# #技能证书获取#

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

import cPickle as p

import time

date = time.strftime('%Y%m%d')

def save_money():

  sav_count=int(raw_input('save money: '))

  sav_comment = raw_input('doing what: ')

  with open('wallet.data') as f:

    balance = p.load(f)

  new_bal = balance + sav_count

  with open('wallet.data','w') as f:

    p.dump(new_bal,f)

  content = '%-12s%-8s%-8s%-10s%-25s\n'%(date,'N/A',sav_count,new_bal,sav_comment)

  with open('record.txt','a')as f:

    f.write(content)

def spend_money():

  spe_count=int(raw_input('spend money: '))

  spe_comment = raw_input('doing what: ')

  with open('wallet.data') as f:

    balance = p.load(f)

  new_bal = balance - spe_count

  with open('wallet.data','w') as f:

    p.dump(new_bal,f)

  with open('record.txt','a')as f:

    content = '%-12s%-8s%-8s%-10s%-25s\n'%(date,spe_count,'N/A',new_bal,spe_comment)

    f.write(content)

def query_info():

  line = '='*63

  content = '%s\n%-12s%-8s%-8s%-10s%-25s'%(line,'Date','Cost','Save','Balance','Comment')

  with open('wallet.data') as f:

    new_bal = p.load(f)

  print 'new balance: ',new_bal

  print content

  with open('record.txt') as f:

    for line in f:

       print line

def show_menu():

  prompt =

  while True:

    CMDs={'0':spend_money,'1':save_money,'2':query_info}

    choice = raw_input('which do you want to do ?%s: '%prompt)

    if choice not in '012':

      break

    CMDs[choice]()

if __name__=='__main__':

  show_menu()

网址:python实现日常记账本小程序 https://www.yuejiaxmz.com/news/view/534280

相关内容

Python实现个人记账系统:高效管理财务的编程实践
【Python】实现一个个人理财助手小程序
6个Python脚本,轻松实现日常任务自动化
python毕设百货超市在线购物小程序小程序端程序+论文
10个Python脚本轻松实现日常任务自动化
10个Python脚本,轻松实现日常任务自动化!
十个Python脚本,轻松实现日常任务自动化
轻松实现日常任务自动化的6个Python脚本
python如何实现日常工作自动化?
python如何改变日常生活

随便看看