ショッピングシステムプログラム練習_PYTHON版
12566 ワード
(python )
# : Python ( C 2013 12 17 《 》)
# : , , , , 。
# :2014.3.22-2014.4.2,2014.7.8-2014.7.9
# :
# :Windows 7 Python3.3.5rc1 IDLE
# python , , , ,
#
import time
import sys
import os
#import users
#
database=[ # , ,
['admin','admin'], #
['luke','123'] #
]
#
goodlist=[ # 、 、
['ID','name','quantity','price','state','discount'],
['001',' ','1000','3.5','0','10'],
['002',' ','200','5','1','9']
]
#
orderlist=['ID','username','name','quantity'] # 、 、
# , 、
class cpr():
def regcpr(self,username,password): # ,
if [username,password] in database:
return 0 # 0
else:
return 1 # 1
def logincpr(self,username,password): # ,
if [username,password] in database: #
if [username,password]==['admin','admin']: # admin admin
return 0 # admin 0
else:
return 1 # admin 1
else:
return 2 # 2
def goodscpr1(self,ID): # , ID ID
print(ID)
for x in range(0,1001):
if ID==goodlist[x][0]:
return 0 # 0
else:
return 1 # 1
def goodscpr2(self,name): # ,
print(name)
for x in range(0,1001):
if name==goodlist[x][1]:
return 0
else:
return 1
#
def order(username):
cls=os.system('cls') #
print(username,", !")
ID=input(" ID :") # ID
goodIDcpr2=cpr()
cprresult3=goodIDcpr2.goodscpr1(ID) #
if cprresult3==1:
quantity2=input(" :")
for x in range(len(goodlist)): # goodlist ID
if goodlist[x][0]!='ID':
key3=goodlist[x]
if key3[0]==ID:
key4=goodlist.index(key3)
price=float(quantity2)*float(goodlist[key4][3])*float(goodlist[key4][5])*0.1 #
name=goodlist[key4][1]
print(" :")
print(username,ID,name,price) #
y=0
key='y'
while(key=='Y' or key=='y'):
y=y+1
key=input(" y :") #
if key=='Y' or key=='y':
print(" ! 。")
orderlist.insert(0,[[ID,username,name,price]]) #
time.sleep(3)
puserGUI(username)
else:
print(" !")
key2=input(" ? 1, , 2 :") #
if key2==1:
puserGUI(username)
if key2==2:
key='y'
else:
print(" , 。") # ID
time.sleep(3)
puserGUI()
#
def goodin():
cls=os.system('cls')
print(" , ! !") #
key='y'
x=0
while(key=='y' or key=='Y'):
x=x+1
ID=input(" ID :") # ID
goodIDcpr=cpr()
cprresult1=goodIDcpr.goodscpr1(ID) # ID
if cprresult1==1:
name=input(" :") #
goodnamecpr=cpr()
cprresult2=goodnamecpr.goodscpr2(name) #
if cprresult2==1:
quantity=input(" :")
price=input(" :")
state=input(" (0 ,1 ):")
discount=input(" (1-10 ,10 ):")
goodlist.insert(0,[ID,name,quantity,price,state,discount])
if x==5:
print(" 5 , ") # 5
time.sleep(3)
auserGUI()
else:
key=input(" ! ? y :")
if key!='y':
print(" ! 。")
auserGUI()
else:
print(" , :")
key='y'
else:
print(" ID , :")
key='y'
#
def regGUI():
cls=os.system('cls')
print(" !")
key1=input(" ? y , 。
") #
if key1=='y' or key1=='Y':
key2='y'
while(key2=='y' or key2=='Y'):
username=input(" :")
password=input(" ")
cpr1=cpr()
result=cpr1.regcpr(username,password) #
if result==0:
print(" ! ! y , :")
key5=input()
key2=key5
elif result==1:
x=1
while(x<6): # , 5
database.insert(0,[username,password])
key4=1
while(key4==1):
result2=cpr1.regcpr(username,password)
if result2==0:
print(" ! 。")
time.sleep(3)
loginGUI()
else:
key4=key4+1
if key4==6:
print(" , , ")
time.sleep(3)
mainGUI()
else:
print(" , ")
time.sleep(3)
x=x+1
else:
mainGUI()
#
def puserGUI(username):
cls=os.system('cls')
print(username,", !") #
key3='y'
while(key3=='y' or key3=='Y'):
print("1. ")
print("2. ")
print("3. ")
key=input(" :") #
if key=='1':
cls=os.system('cls')
for x in range(len(goodlist)):
print(goodlist[x])
print("1. ")
print("2. ")
key2=input(" :")
x=1
while(x==1):
if key2=='1':
order(username)
elif key2=='2':
mainGUI()
else:
print(" , 。")
x='1'
elif key=='2':
order(username)
elif key=='3':
mainGUI()
else:
print(" , :")
key3='y'
#
def auserGUI():
cls=os.system('cls')
print(" , !")
print("1. ")
print("2. ")
print("3. ")
key=input(" :")
if key=='1':
cls=os.system('cls')
for x in range(len(goodlist)):
print(goodlist[x])
print("1. ")
print("2. ")
key2=input(" :")
x=1
while(x==1):
if key2=='1':
goodin()
elif key2=='2':
mainGUI()
else:
print(" , 。")
time.sleep(2)
elif key=='2':
goodin()
elif key=='3':
mainGUI()
#
def loginGUI():
cls=os.system('cls')
print("1. ")
print("2. ")
print("3. ")
key=input(" :")
if key=='1':
print(" !")
key2='y'
while(key2=='y' or key2=='Y'):
username=input(" :")
password=input(" :")
cpr2=cpr()
result=cpr2.logincpr(username,password) #
if result==0:
auserGUI()
elif result==1:
puserGUI(username)
elif result==2:
print(" , , 。")
time.sleep(3)
mainGUI()
if key=='2':
mainGUI()
if key=='3':
print(" !")
time.sleep(3)
sys.exit()
#
def mainGUI():
cls=os.system('cls')
key='y'
while key=='y' or key=='Y':
print('1. ')
print('2. ')
print('3. ')
ordnum=input(" :
")
if ordnum=='1':
regGUI()
elif ordnum=='2':
loginGUI()
elif ordnum=='3':
sys.exit()
else:
key=input(" , ? y, 。")
#
print(" !") #
time.sleep(2) # 2
mainGUI() #