python高级ShoppingSystem

1、商城类
属性:商品列表及单价、货款
方法:售出商品
2、仓库类
属性:商品列表及对应库存
方法:出货、进货
3、采购员
属性:货款、采购列表及单价
方法:进货

class Shop:
def init(self,store,procurement):
self.shopList=[{‘name’:‘华为’,‘price’:4498}
,{‘name’:‘苹果’,‘price’:6698}
,{‘name’:‘小米’,‘price’:2498}]
self.money = 100000
self.store = store
self.procurement = procurement
def sellShopping(self,name,num):
result = self.store.sell_store(name,num)
if result == ‘OK’:
for l in self.shopList:
for v in l.values():
if v == name:
print(‘应收金额:%d’%(l[‘price’]*num))
self.money += l[‘price’]*num
for l in self.store.storeList:
for v in l.values():
if v == name:
l[‘count’] = l[‘count’] - num
print(‘当前收款余额:’,self.money)
print(‘当前库存信息:\n’,self.store.storeList)
return ‘请您收好物品,欢迎下次光临!’
elif result == ‘库存不足’:
print(‘抱歉,库存不足,已通知进货!’)
money = self.store.buy_store(self.procurement,self.money,name,num)
if self.money != money:
self.money = money
print(‘进货后剩余金额:%d’%self.money)
for l in self.store.storeList:
for v in l.values():
if v == name:
l[‘count’] = num
print(‘进货后剩余库存:%d’%l[‘count’])
return’进货成功,欢迎您再次前来购买!’
else:
return ‘进货失败,金额不足!’
else:
return result

class Store:
def init(self):
self.storeList=[{‘name’:‘华为’,‘count’:100}
,{‘name’:‘苹果’,‘count’:50}
,{‘name’:‘小米’,‘count’:150}]

def buy_store(self,procurement,money,name,num):
	for l in self.storeList:
		for v in l.values():
			if v == name:
				count = num - l['count']
	return procurement.procurement_shopping(money,name,count)
def sell_store(self,name,num):
	isExist = False
	for l in self.storeList:
		for v in l.values():
			if v == name:
				isExist = True
				if l['count'] >= num:
					return 'OK'
				else:
					return '库存不足'
	if not isExist:
		return '抱歉,无此商品!'

class Procurement:
def init(self):
self.procurementList=[{‘name’:‘华为’,‘price’:3498}
,{‘name’:‘苹果’,‘price’:5698}
,{‘name’:‘小米’,‘price’:1598}]
def procurement_shopping(self,money,name,num):
for l in self.procurementList:
for v in l.values():
if v == name:
if money < num * l[‘price’]:
print(‘金额不足,采购失败!’)
else:
money -= num * l[‘price’]
print(‘采购成功,采购数量:%d部,花费金额:%d元’%(num,num * l[‘price’]))
return money

storer = Store()
procurement = Procurement()
shopper = Shop(storer,procurement)

while True:
print(‘欢迎光临’)
print(‘商品信息:’)
for l in shopper.shopList:
print(‘商品名称:’+l[‘name’]+’ 商品单价:’,l[‘price’],‘元’)
name = input(‘请输入您要购买的手机商品的名称:’)
count = int(input(‘请输入您要购买的数量:’))
print(shopper.sellShopping(name,count))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值