python学习备忘之编写一个信用卡程序

需求分析如下图所示:这里难点就是现金的替换。我这里的思路是每当使用现金的时候。把用户文件的行变成一个列表,在转换成int类型相加减:得到结果之后用fileinput模块进行替换。下面的步骤流水账还在思考当中。当然提现手续费换算很简单,我这里也没有列出,大致已经完成了。取现。充值。购物等三个功能:(由于是运维所以代码很粗糙)

wKioL1Q95aPQ5iYrAAHrTcWBpMQ162.jpg

#!/usr/bin/python
import fileinput
while True:
        name=raw_input("please input name:").strip()
        if name !="xiaoluo":
                        print "please try agine:"
                        continue
        password=raw_input("please input your password:").strip()
        if password !="123456":
                        print "please try agine:"
                        continue
        break
while True:
        print "1.check money"
        print "2.shopping"
        print "3.take money"
        print "4.add money"
        print "5.check bill"
        print "6.exit"
        chose=raw_input("choose:")
        if chose == "1":
                f= open('/python/atmuser.txt')
                c=f.readlines()
                for line in c:
                        print line
        if chose == "2":
                chooping = []
                shmoney = []
                fi=file('shopping.txt')
                for lines in fi.readlines():
                        p = lines.split()[0]
                        m = lines.split()[1]
                        chooping.append(p)
                        shmoney.append(m)
                print chooping,shmoney
#       buy=raw_input("you can buy thing in this:")
                print "0.       car     20000"
                print "1.       coffee  350"
                print "2.       clothes 2000"
                print "3.       bike    2500"
                print "4.       maotai  10000"
                buy=int(raw_input("you can buy thing in this:"))
                f=open('/python/atmuser.txt')
                for c in f.readlines():
                        usermoney=c.split()[1]
                        print usermoney
                        if int(usermoney)> int(shmoney[buy]) :
                                sert=int(usermoney)-int(shmoney[buy])
                                usermoney=str(sert)
                                print usermoney
#                               e=open('/python/atmuser.txt')
#                               for d in e.readlines():
#                                       dmoney=d.split()
#                                       dmoney[1]=str(usermoney)
#                                       print dmoney
                                for line in fileinput.input('/python/atmuser.txt',inplace=1):
                                                line =line.replace(c.split()[1],usermoney)
                                                print line,
                        else:
                                print "your does have no enough money"
        if chose =="3":
                tmoney=raw_input("please input your amoney of money:")
                f=open('/python/atmuser.txt')
                for c in f.readlines():
                        usermoney=c.split()[1]
                        if int(usermoney)>int(tmoney):
                                  sert=int(usermoney)-int(tmoney)
                                  usermoney=str(sert)
                                  for line in fileinput.input('/python/atmuser.txt',inplace=1):
                                                line =line.replace(c.split()[1],usermoney)
                                                print line,
        if chose =="4":
                amoney=raw_input("please input add your amoney of money:")
                f=open("/python/atmuser.txt")
                for c in f.readlines():
                        usermoney=c.split()[1]
                        sert=int(usermoney)+int(amoney)
                        usermoney=str(sert)
                        for line in fileinput.input('/python/atmuser.txt',inplace=1):
                                                line =line.replace(c.split()[1],usermoney)
                                                print line,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值