#/user/bin/env python
#-*-coding:utf-8-*-
"家庭理财程序"
import os
family_account = 'account.cfg'
def Home():
"""主页菜单"""
menu = """
储蓄(Savings ...s)
支票(Check ...k)
金融市场(The financial markets ...m)
退出(Exit ...e)
请选择:
"""
items = {'s' : '储蓄', 'k' : '支票', 'm' : '金融市场', 'e' : '退出'}
while True:
try:
choice = raw_input(menu).strip()[0].lower()
except EOFError, KeyboardInterrupt:
choice = 'e'
if choice not in 'skme':
print 'invalid option, try again'
continue
else:
print '进入[%s]页面' % items[choice]
if choice == 's':
Saving()
elif choice == 'k':
pass
elif choice == 'm':
pass
elif choice == 'e':
break
def Saving():
'''储存页面'''
menu = """
存款(Deposit ...d)
取款(Withdrawal ...w)
借款(Borrow money ...b)
贷款(Loans ...l)
取消(Cancel ...c)
请选择:
"""
items = {'d' : '存款', 'w' : '取款', 'b' : '借款', 'l' : '贷款', 'c' : '取消'}
savings = {'deposit' : 0.0, "borrow" : 0.0, 'loans' : 0.0}
while True:
try:
choice = raw_input(menu).strip()[0].lower()
except EOFError, KeyboardInterrupt:
choice = 'e'
if choice not in 'dwblc':
print 'invalid option, try again'
continue
else:
print '进入[%s]页面' % items[choice]
if choice == 'd':
Deposit()
elif choice == 'w':
Withdrawal()
elif choice == 'b':
pass
elif choice == 'l':
pass
elif choice == 'c':
break
def ReadAccount():
account_info = {}
if not os.path.exists(family_account):
return account_info
f = open(family_account, "r")
for eachline in f:
pos = eachline.find('=')
if pos == -1:
continue
key = eachline[0:pos]
value = eachline[pos+1 : -1]
account_info[key] = float(value)
f.close()
return account_info
def SaveAccount(account_info):
f = open(family_account, "w")
item = ""
for key, value in account_info.items():
item = key
item += "="
item += str(value)
f.write(item)
f.close()
return True
def Deposit():
deposit = 0.0
account = ReadAccount()
if "deposit" in account.keys():
deposit = account["deposit"]
print "你的存款余额有:¥%.2f" % deposit
money = raw_input("放入存款金额:")
money = float(money)
if money < 0.0:
return
print "开始存款 ...请稍后"
deposit += money
account["deposit"] = deposit
SaveAccount(account)
print "存款成功..."
def Withdrawal():
balance = 0.0
account = ReadAccount()
if "deposit" in account.keys():
balance = account["deposit"]
print "你的存款余额有:¥%.2f" % balance
money = raw_input("输入取款金额:")
money = float(money)
if money < 0.0:
print "取款结束"
return
print "开始取款 ...请稍后"
balance -= money
if balance <= 0.0:
print "余额不足"
return
account["deposit"] = balance
SaveAccount(account)
print "本次取款为 : ¥%.2f" % money
if __name__ == '__main__':
Home()
简单的家庭理财程序
最新推荐文章于 2024-09-19 22:04:53 发布