模拟一个企业的经营。企业共有3000件库存,每天限量销售100件,要是当天需求超过了100件则不销售,低于限量100件就当作剩余库存继续保留。现在要求我们模拟10次,统计每天限量销售条件生效的平均天数,以及损失的平均客户需求总量;相反的,要是统计条件不生效的平均天数,以及在限量下剩余的平均可销售需求
时间: 2024-02-13 22:02:40 浏览: 27
好的,下面是一个Python模拟企业经营的程序:
```python
import random
# 初始库存
inventory = 3000
# 限量销售量
limit = 100
# 统计数据
effective_days = 0
ineffective_days = 0
loss_demand = 0
remaining_demand = 0
# 模拟10次
for i in range(10):
# 当天需求
demand = random.randint(50, 150)
# 判断是否销售
if demand <= limit and inventory >= limit:
inventory -= limit
effective_days += 1
remaining_demand += limit - demand
else:
ineffective_days += 1
loss_demand += demand
# 输出当天销售情况
print('第', i+1, '天销售情况:')
print(' 库存:', inventory)
print(' 需求:', demand)
# 计算统计数据
avg_effective_days = effective_days / 10
avg_loss_demand = loss_demand / ineffective_days
avg_ineffective_days = ineffective_days / 10
avg_remaining_demand = remaining_demand / effective_days
# 输出统计结果
print('限量销售条件生效的平均天数:', avg_effective_days)
print('损失的平均客户需求总量:', avg_loss_demand)
print('限量销售条件不生效的平均天数:', avg_ineffective_days)
print('在限量下剩余的平均可销售需求:', avg_remaining_demand)
```
这个程序模拟了10天企业的经营情况,每天随机生成一个50到150的需求量,然后根据需求量和库存量判断是否销售。如果当天需求量小于等于限量并且库存量足够,则销售100件商品,并计算剩余可销售需求量。如果当天需求量大于限量或者库存量不足,则不销售,并计算损失的客户需求量。
最后,程序输出每天的销售情况,并计算出限量销售条件生效的平均天数、损失的平均客户需求总量、限量销售条件不生效的平均天数和在限量下剩余的平均可销售需求。你可以根据需要修改代码中的初始库存量、限量销售量和模拟天数。
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)