Warehouse class
the Repository class ():
L = { 'killing Blade': [3900,20],
'shadowless sword - Ai Leinuo': [3788,22],
'meridional Seven Star': [3899,19],
'Jian Shen Foil beam months': [3688,22]}
DEF the Add (Self, One):
IF List (one.name.keys ()) [0] Not in Repository.l:
Repository.l [List (one.name .keys ()) [0]] = List (one.name.values ())
the else:
A = one.name
B = List (a.keys ()) [0]
Repository.l [B] [-. 1] =. 1 +
Print ( 'complete')
DEF Sub (Self, One):
IF List (one.name.keys ()) [0] not in Repository.l:
Print ( 'without the product')
elif list(one.name.keys())[0] == 1:
Repository.l.remove(one.name)
else:
a = one.name
b = list(a.keys())[0]
Repository.l[b][-1] -= 1
print()
def show(self):
n = 0
for i,k in Repository.l.items():
n += 1
print('%d 商品:%-14s\t价格:%-5s \t数量:%-3s' % (n,i, k[0],k[-1]))
class Commdity(Repository):
def init(self, name = None, price = None, count = None):
self.name = name
self.price = price
self.count = count
def shop(self):
return Repository.l
User class
the Customer class ():
Sala = 50000
DEF Chongzhi (Self, Money):
Customer.sala Customer.sala + = int (Money)
Print ( 'successful recharge, there are now membered% s'% self.sala)
Login class
Loggin class (Customer):
ls = {( '1', '2'): 3}
def init (self, cid, pwd, name = None):
self.cid cid =
self.pwd pwd =
self.name name =
def login(self):
if (self.cid, self.pwd) in list(Loggin.ls.keys()):
print('登录成功')
return Loggin(self.cid,self.name, self.pwd)
else:
print('账号密码输入错误')
return
Logup class ():
DEF logup (Self, pwd, name):
Import Random
the while True:
CIDS the random.randint = (10000,99999)
IF CIDS Not in Loggin.ls:
Loggin.ls [STR (CIDS), pwd] = name
Print ( 'successful registration')
Print ( 'your account: \ nid:% - 10s \ n password:% - 10s \ n name:% - 10s'% (CIDS, pwd, name))
BREAK
the else:
the Continue
shopping cart
Shopcar class (the Customer):
L = {}
DEF the Add (Self, One):
IF Customer.sala <= List (one.name.values ()) [0] [0]:
Print ( 'please recharge')
the else:
List IF (one.name.keys ()) [0] Not in Shopcar.l:
Print ( 'Yes')
Shopcar.l [List (one.name.keys ()) [0]] = List (one.name .values ()) [0]
Customer.sala - List = (one.name.values ()) [0] [0]
Print ( 'purchase completion, your goods are% S, balance:% s element'% (Shopcar.l, Customer.sala))
else:
print(Shopcar.l[list(one.name.keys())[0]])
Shopcar.l[list(one.name.keys())[0]][-1] += 1
Customer.sala -= list(one.name.values())[0][0]
print('购买完成,你的商品都有%s,余额:%s元' % (Shopcar.l,Customer.sala) )
def sub(self, one):
if list(one.name.keys())[0] not in Shopcar.l:
print('没有对应的商品')
elif Shopcar.l[list(one.name.keys())[0]][-1] == 1:
Shopcar.l.remove(list(one.name.keys())[0])
Customer.sala += list(one.name.values())[0][0]
print('移除成功,你的商品都有%s,余额:%s元' % (Shopcar.l,Customer.sala) )
else:
Shopcar.l[list(one.name.keys())[0]][-1] -= 1
Customer.sala += list(one.name.values())[0][0]
print('移除成功,你的商品都有%s,余额:%s元' % (Shopcar.l,Customer.sala) )
Equipment interface class
class Someequ():
def init(self, name):
self.name = name
def out_equ(self):
return self.name
Interface classes
Io class ():
DEF Trans (Self, Inputs, choices):
IF choices == '. 1':
return { 'killing Blade': [3900,0]}
elif choices == '2':
return { 'shadowless sword - Ai Leinuo ': [3788,0]}
elif choices =='. 3 ':
return {' meridional Seven Star ': [3899,0]}
elif choices =='. 4 ':
return {' Jianshen beam month Foil ': [3688,0]}
the else:
Print (' invalid parameter ')
Enter the class
class the Log ():
DEF ID (Self):
IDS = INPUT ( 'Enter ID:')
return IDS
DEF MIMA (Self):
mA = INPUT ( 'Enter password:')
return mA
DEF mingzi (Self):
MZ = input ( 'Please enter the name:')
return MZ
DEF xuanxiang (Self):
xx = input ( 'enter the options:')
return xx
DEF xuanze (Self):
the xz = input ( 'Please choose:')
return the xz
print ( 'Welcome' .center (50, '*'))
the while True:
print ( 'Please select Register or Log')
print ( '. 1 registration')
print ( '. 2 Login')
log = the Log ()
log.xuanxiang = XX ()
IF == XX '. 1':
# registered
print ( 'Welcome to register')
B = log.mima ()
C = log.mingzi ()
loggin = Logup ()
logs2 loggin.logup = (B , C)
Continue
elif XX == '2':
# Log
print ( 'Login')
A = log.id ()
B = log.mima ()
loggin loggin = (A, B)
logs = loggin.login ( )
IF logs = None:!
the while True:
Print ( 'Please select the option:')
Print ( '. recharge 1')
Print ( '. 2 purchases')
Print ( '. 3 removal of merchandise')
Print ( '. 4. Exit')
log = the Log ()
log.xuanxiang = XX ()
IF == XX '. 1':
# recharge
log = the Log ()
an xz = log.xuanze ()
Chongzhi = the Customer ()
chongzhi.chongzhi (an xz)
elif xx == '2':
#购买
commdity = Commdity()
shoplist = commdity.shop()
repository = Repository()
repository.show()
log = Log()
xz = log.xuanze()
io = Io()
ios = io.trans(shoplist,xz)
pack_equ = Someequ(ios)
shopcar = Shopcar()
shopcar.add(pack_equ)
repository.sub(pack_equ)
elif xx == '3':
#移除
commdity = Commdity()
shoplist = commdity.shop()
repository = Repository()
repository.show()
log = Log()
xz = log.xuanze()
io = Io()
ios = io.trans(shoplist,xz)
pack_equ = Someequ(ios)
shopcar = Shopcar()
shopcar.sub(pack_equ)
repository.add(pack_equ)
elif xx == '4':
#退出
print('欢迎下次光临')
exit()
else:
print('无效的选择。请重新选择')
print('')
else:
print('请重新输入')
input('')
else:
print('无效的选择,请重新输入')
input('')