标签:line use print import 购物车 lines rip user sdi
用户段:
# -*- coding:utf-8 -*-
shop_line={}
info_user={}
shop_car=[]
import re
for line in open(‘C:\Users\Administrator.SKY-20140501YNV\Desktop\sshop.txt‘):
line=line.rstrip(‘\n‘)
key=re.split(":",line)
shop_line[key[0]]=key[1]
for line in open(‘C:\Users\Administrator.SKY-20140501YNV\Desktop\info.txt‘):
line=line.rstrip(‘\n‘)
key=line.split(":")
info_user[key[0]]=key[1]
user_name=raw_input("请用户输入用户名》")
if user_name in info_user:
salary=info_user[user_name]
salary=int(salary)
else:
while True:
salary=raw_input("请输入您的工资:")
if salary.isdigit():
salary=int(salary)
lines=‘:‘.join([user_name,str(salary)])
open(‘C:\Users\Administrator.SKY-20140501YNV\Desktop\info.txt‘,‘a‘).write(‘\n‘)
open(‘C:\Users\Administrator.SKY-20140501YNV\Desktop\info.txt‘, ‘a‘).write(lines)
break
while True:
for i in shop_line:
print i,shop_line[i]
chioce=raw_input("请用户输入选择的商品,若想退出,请输入q》")
if chioce==‘q‘:
print shop_car,salary
lines=open(‘C:\Users\Administrator.SKY-20140501YNV\Desktop\info.txt‘,‘r‘).readlines()
flen=len(lines)
for i in range(flen):
m=re.match(user_name,lines[i])
if m is not None:
lines[i]=‘:‘.join([user_name,str(salary)])
open(‘C:\Users\Administrator.SKY-20140501YNV\Desktop\info.txt‘,‘w‘).writelines(lines)
break
elif chioce in shop_line and salary-int(shop_line[chioce])>=0:
shop_car.append(chioce)
salary-=int(shop_line[chioce])
标签:line use print import 购物车 lines rip user sdi
原文地址:http://www.cnblogs.com/date20170814/p/7400294.html