标签:password continue 信用卡 xiaoluo python
需求分析如下图所示:这里难点就是现金的替换。我这里的思路是每当使用现金的时候。把用户文件的行变成一个列表,在转换成int类型相加减:得到结果之后用fileinput模块进行替换。下面的步骤流水账还在思考当中。当然提现手续费换算很简单,我这里也没有列出,大致已经完成了。取现。充值。购物等三个功能:(由于是运维所以代码很粗糙)
#!/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,
本文出自 “小罗” 博客,请务必保留此出处http://xiaoluoge.blog.51cto.com/9141967/1564240
标签:password continue 信用卡 xiaoluo python
原文地址:http://xiaoluoge.blog.51cto.com/9141967/1564240