什么鬼购物车

仓库类

class Repository():
l = {'屠戮之刃':[3900,20],
'无影剑-艾雷诺':[3788,22],
'子午七星剑':[3899,19],
'剑神梁月的钝剑':[3688,22]}
def add(self, one):
if list(one.name.keys())[0] not in Repository.l:
Repository.l[list(one.name.keys())[0]] = list(one.name.values())
else:
a = one.name
b = list(a.keys())[0]
Repository.l[b][-1] += 1
print('完成')
def sub(self, one):
if list(one.name.keys())[0] not in Repository.l:
print('没有该商品')

    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

用户类

class Customer():
sala =50000
def chongzhi(self, money):
Customer.sala = Customer.sala + int(money)
print('充值成功,现在共有%s元' % self.sala)

登录类

class Loggin(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

class Logup():
def logup(self, pwd, name):
import random
while True:
cids = random.randint(10000,99999)
if cids not in Loggin.ls:
Loggin.ls[str(cids),pwd] = name
print('注册成功')
print('你的账号:\nid:%-10s\n密码:%-10s\n 名字:%-10s' % (cids,pwd,name))
break
else:
continue

购物车

class Shopcar(Customer):
l = {}
def add(self, one):
if Customer.sala <= list(one.name.values())[0][0]:
print('请充值')
else:
if list(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('购买完成,你的商品都有%s,余额:%s元' % (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) )

装备接口类

class Someequ():
def init(self, name):
self.name = name
def out_equ(self):
return self.name

接口类

class Io():
def trans(self, inputs, choices):
if choices == '1':
return {'屠戮之刃':[3900,0]}
elif choices == '2':
return {'无影剑-艾雷诺':[3788,0]}
elif choices == '3':
return {'子午七星剑':[3899,0]}
elif choices == '4':
return { '剑神梁月的钝剑':[3688,0]}
else:
print('无效参数')

输入类

class Log():
def id(self):
ids = input('请输入id:')
return ids
def mima(self):
ma = input('请输入密码:')
return ma
def mingzi(self):
mz= input('请输入名字:')
return mz
def xuanxiang(self):
xx = input('请输入选项:')
return xx
def xuanze(self):
xz = input('请选择:')
return xz

print('欢迎光临'.center(50,'*'))
while True:
print('请选择注册或者登录')
print('1. 注册')
print('2. 登录')
log = Log()
xx = log.xuanxiang()
if xx == '1':
#注册
print('欢迎注册')
b = log.mima()
c = log.mingzi()
loggin = Logup()
logs2 =loggin.logup(b,c)
continue
elif xx == '2':
#登录
print('请先登录')
a = log.id()
b = log.mima()
loggin = Loggin(a,b)
logs = loggin.login()
if logs != None:
while True:
print('请选择选项:')
print('1.充值')
print('2.购买商品 ')
print('3.移除商品')
print('4.退出')
log = Log()
xx = log.xuanxiang()
if xx == '1':
#充值
log = Log()
xz = log.xuanze()
chongzhi = Customer()
chongzhi.chongzhi(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('')

posted on 2019-07-24 08:14  幻嘤剑舞  阅读(62)  评论(0编辑  收藏  举报

导航