python 购物流程脚本
#!/usr/bin/env python# Descript message
# Author:Allentuns
# MailBox:zhengyansheng@hytyi.com
# Tel:13260071987
import startup
import sys
userfile = open("user.txt","r")
rss = userfile.readlines()
listpass = []
for line in rss:
line1 = line.split()
listpass.append(line1)
username1 = listpass
password1 = listpass
while True:
user = raw_input("please input your username:")
user_num = username1.index(user)
user_pas = password1
if len(user) == 0:
print "empty user,try again."
continue
elif user in username1:
break
elif user == "q" or user == "quit" or user == "exit":
print "Welcome to come again next time"
sys.exit()
else:
print "%s is not exists,please try again input your name" %(user)
continue
while True:
passwdd = raw_input("please your password:")
if len(passwdd) == 0:
print "Sorry , input your password error , please try again."
#elif passwdd in password1:
elif passwdd == user_pas:
print "\n" + "Welcome to %s login shoppings:" %(user)
break
else:
print "password is Error,please try again."
while True:
try:
salary = int(raw_input("please input your salary:"))
break
except ValueError:
print "please input a number,not string."
file = open('shoplist.txt','r')
for fr in file:
fr = fr.rstrip()
print fr
file.close()
print """Options and arguments:
input "D" : Delete from shoplist into del
input "F" : Return to the total pages
input "T" : Total shoplist"""
products = []
prices = []
file2 = open('shoplist.txt')
fr2 = file2.readlines()
for line in fr2:
p1 = line.split()
p2 = int(line.split())
products.append(p1)
prices.append(p2)
prices = prices
list00 = []
while True:
choose = raw_input("please choose your buy things:")
if choose in products:
product_num = products.index(choose)
product_price = prices
if salary > product_price:
print "%s $%d" %(choose,product_price)
list00.append(choose)
print "Add %s into your shoplist" %(choose)
print "You choose to purchase the commodity list:",list00
salary = salary - product_price
else:
if salary < min(prices):
print "Sorry , reset of your salary cannot buy anythings."
sys.exit()
elif choose == "T":
print "salary left :$%s" %(salary)
print "You choose to purchase the commodity list:",list00
sys.exit()
elif choose == "D":
while True:
delchoose = raw_input("your will things remove from into shoplist:")
if delchoose in products:
product_num2 = products.index(delchoose)
product_price2 = prices
salary = salary + product_price2
list00.remove(delchoose)
print list00
print salary
break
页:
[1]