{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Week 2 - Assignment\n",
"## Example Solution\n",
"\n",
"In this exercise you are going to simulate a sales and operations planning\n",
"using the [zero stock level](https://help.sap.com/docs/SAP_S4HANA_ON-PREMISE/d853922bdd584e8e83027e5a0b8122f2/d06dbd534f22b44ce10000000a174cb4.html?locale=en-US)\n",
"strategy. Write a Python program that asks the user to enter the following data:\n",
"\n",
"- An initial stock level for a product\n",
"- The number of month(s) to plan\n",
"- The planned sales quantity for each month\n",
"\n",
"Based on this data, calculate the required production quantity as follows:\n",
"\n",
"- If the sales quantity is smaller than the stock level of the previous month, the production quantity is 0\n",
"- If the sales quantity is larger than the stock level of the previous month, the production quantity is this difference\n",
"\n",
"Below is an example execution of the program:\n",
"\n",
" Please enter an initial stock level: 500\n",
" Please enter the number of month to plan: 5\n",
" Please enter the planned sales quantity: 300\n",
" Please enter the planned sales quantity: 250\n",
" Please enter the planned sales quantity: 200\n",
" Please enter the planned sales quantity: 400\n",
" Please enter the planned sales quantity: 100\n",
"\n",
" The resulting production quantities are:\n",
" Production quantity month 1 - 0\n",
" Production quantity month 2 - 50\n",
" Production quantity month 3 - 200\n",
" Production quantity month 4 - 400\n",
" Production quantity month 5 - 100\n",
"\n",
"Why are those production quantities calculated? The initial stock level is 500. In the first month 300 pieces are sold.\n",
"Therefore, nothing needs to be produced and the resulting stock is 200 (= 500 - 300).\n",
"In the second month 250 pieces are sold. The stock level after the previous month is 200. Therefore 50 pieces need to be\n",
"produced. The resulting stock level is 0 (= 200 + 50 - 250).\n",
"In the third month 200 pieces are sold. The stock level after the previous month is 0. Therefore 200 pieces need to be\n",
"produced. The resulting stock level is 0 (= 200 - 200).\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stock = int(input(\"Please enter an initial stock level: \"))\n",
"num_months = int(input(\"Please enter the number of month to plan: \"))\n",
"\n",
"sales_quantity = []\n",
"for month in range(num_months):\n",
" sq = int(input(\"Please enter the planned sales quantity: \"))\n",
" sales_quantity.append(sq)\n",
" \n",
"production_quantity = []\n",
"for month in range(num_months):\n",
" if stock >= sales_quantity[month]:\n",
" production_quantity.append(0)\n",
" stock -= sales_quantity[month]\n",
" else:\n",
" production = sales_quantity[month] - stock\n",
" stock = 0\n",
" production_quantity.append(production)\n",
"\n",
"for month in range(num_months):\n",
" print(\"Production quantity month\", month, \"-\", production_quantity[month])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}