日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

用python写一个记账小程序_python实现日常记账本小程序

發(fā)布時間:2025/3/19 python 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用python写一个记账小程序_python实现日常记账本小程序 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

python實現(xiàn)收支的自動計算,能夠查詢每筆賬款的消費詳情,具體內(nèi)容如下

1、函數(shù)需要兩個文件:一個類似錢包功能,存放錢;另一個用于記錄每筆花銷的用途

#!/usr/bin/env python

import cPickle as p

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

p.dump(10000,f)

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

pass

2、功能實現(xiàn)

#!!/usr/bin/env python

#coding:utf8

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 = '''''

'0':'spend_money'

'1':'save_money'

'2':'query_info'

'3':'quit'

'''

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()

3、程序還有改進處,例如將兩個文件以參數(shù)的形式傳入,會簡化代碼。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持找一找教程網(wǎng)。

總結(jié)

以上是生活随笔為你收集整理的用python写一个记账小程序_python实现日常记账本小程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。