现在,我想简单计算网页设计公司按照以下标准在一年内赚取多少利润:
该公司销售主题,插件和设计。
每个主题的费用为20,插件费用为10,设计费用为50
公司每周稳定维持5个主题,4个插件和2个设计的总销售额(固定金额)
最近,该公司设法每周销售额外的项目,如下所示>>
在第1周,他们销售5个主题,4个插件和2个设计(默认)
在第2周,他们销售6个主题,5个插件和3个设计
在第3周,他们销售7个主题,6个插件和4个设计 等。
以下是我设法创建的代码(我想知道公司每周会根据上述顺序做多少)
design_sales = 2
theme_sales = 5
plugin_sales = 4
design_price = 50
theme_price = 20
plugin_price = 10
design_profit = design_sales * design_price
theme_profit = theme_sales * theme_price
plugin_profit = plugin_sales * plugin_price
firstWeekSales = design_profit + theme_profit + plugin_profit
WeeklyIncrease = firstWeekSales - (theme_price + plugin_price + design_price)
for week in range(1,53):
WeeklyIncrease = WeeklyIncrease + theme_price + plugin_price + design_price
print('Week %s = %s' % (week, WeeklyIncrease))
我这样做后如何计算整年的利润?
答案 0 :(得分:0)
第一步是将数据组织到字典或列表中。以下是使用列表的示例:
# list of tuples (themes, plugins, designs) with week-1 as the index
weekly_sales_quantity = [
(5, 4, 2),
(6, 5, 2),
]
下一步是初始化,迭代和总结年初至今(ytd):
theme_price = 20
plugin_price = 10
design_price = 50
theme_sales_ytd = 0
plugin_sales_ytd = 0
design_sales_ytd = 0
for week in weekly_sales_quantity:
theme_quantity, plugin_quantity, design_quantity = week
theme_sales = theme_quantity * theme_price
plugin_sales = theme_quantity * theme_price
design_sales = theme_quantity * theme_price
theme_sales_ytd += theme_sales
plugin_sales_ytd += plugin_sales
design_sales_ytd += design_sales
答案 1 :(得分:0)
假设一个月有4个星期。在第四周,他们销售5个主题,4个插件和2个设计(默认)。
这是代码。
design_sales = 2
theme_sales = 5
plugin_sales = 4
design_price = 50
theme_price = 20
plugin_price = 10
yearly_profit = 0
for month in range(0,12):
for week in range(0,3):
# calculate weekly profit for each product
design_profit = design_sales * design_price
theme_profit = theme_sales * theme_price
plugin_profit = plugin_sales * plugin_price
# add weekly profit to yearly profit
yearly_profit += (design_profit + theme_profit + plugin_profit)
# accumulate extra sale
design_sales += 1
theme_sales += 1
plugin_sales += 1
# fourth week
design_sales = 2
theme_sales = 5
plugin_sales = 4
# profit for fourth week
design_profit = design_sales * design_price
theme_profit = theme_sales * theme_price
plugin_profit = plugin_sales * plugin_price
# add fourth week profit to yearly profit
yearly_profit += (design_profit + theme_profit + plugin_profit)
print(yearly_profit)