python核心编程第九章(9-10)

来源:互联网 发布:单片机 液晶屏与电机 编辑:程序博客网 时间:2024/05/23 15:56
import ConfigParser
def financial():
    """9–10. 家庭理财.创建一个家庭理财程序. 你的程序需
    要处理储蓄, 支票, 金融市场, 定期存款等多种帐户.为每
    种帐户提供一个菜单操作界面, 要有存款, 取款, 借,贷等
    操作. 另外还要提供一个取消操作选项. 用户退出这个程序
    时相关数据应该保存到文件里去(出于备份的目的,程序执行
    过程中也要备份.)"""
    prompt ='''
    (S)avings
    (C)heck
    (F)inancial market
    (D)eposit
    (E)xit
    Enter your selection:'''
    function ='''
    (s)avings
    (d)raw
    (b)orrow
    (l)oan
    Enter your selection:'''
    account = {'s':'Savings','c':'Check','f':'Financial','d':'Deposit'}
    fun = {'s':'savings','d':'draw','l':'loan','b':'borrow'}
    cf = ConfigParser.ConfigParser()
    cf.read('FamilyAccount.ini')
    enter = raw_input(prompt).strip()[0].lower()
    while True:
          if enter in 'scfd':
               print 'Welcome %s business!' %account[enter].lower()
               section = account[enter]
               select = raw_input(function).strip()[0].lower()
               if select in 'sdbl':
                   print 'Welcome %s business!' %fun[select]
                   key = fun[select]
                   monkey = int(raw_input\
                   ('Enter amount of money <must be digit.>:').strip())
                   cf.set(section,key,monkey)
                   cancel = raw_input('Cancel,please press "c" ...\n')
                   if cancel == 'c': return False
                   else:
                       fp = open('FamilyAccount.ini','w')
                       cf.write(fp)
                       fp.close()  
          elif enter == 'e':return False
          else: print 'Invalid operation,try again!'
0 0
原创粉丝点击