{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple Function Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Executing the cell below will render wide...



  • Complete the missing code in the function definitions that are given in the notebook that I shared after last week's lecture. Execute the cells to check if the correct results are produced.

  • Create an Excel sheet that optimizes the simple optimization problem that we discussed in class (see book and lecture slides)




{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple Function Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Executing the cell below will render wide cells" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ ".container {width:95% !important;}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.core.display import display, HTML\n", "display(HTML(\".container {width:95% !important;}\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The NetProfit function below returns the net profit given: \n", "- sales price (per unit)\n", "- Total fixed cost\n", "- Labor cost (per unit)\n", "- Parts cost (per unit)\n", "- Total quantity of units sold\n", "\n", " " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def NetProfit(sales_price, fixed_cost, labor_cost, parts_cost, units_sold):\n", "\n", " return profit" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Revenue function below returns the total revenue given: \n", "- Sales price (per unit)\n", "- Total quantity of units sold" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def Revenue(sales_price, units_sold):\n", "\n", " return revenue" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The VariableCost function below returns the total variable cost given: \n", "- Labor cost (per unit)\n", "- Parts cost (per unit)\n", "- Total quantity of units sold" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def VariableCost(labor_cost, parts_cost, units_sold):\n", "\n", " return cost" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the below cell we assign values entered by the user to all variables required to calculate the net profit " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "sales_price = 100\n", "cost_fixed = 1000000\n", "labor = 35\n", "parts = 20\n", "product_sold = 50000" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the cell below we pass in all required variables, execute the NetProfit function, and print its ouput" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1250000\n" ] } ], "source": [ "print(NetProfit(sales_price, cost_fixed, labor, parts, product_sold))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the cell below we just call the NetProfit function. Jupyter displays the output 'automatically'. Note the difference in output in just calling the function and explicitly printing the output of the function" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "1250000" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "NetProfit(sales_price, cost_fixed, labor, parts, product_sold)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the cell below we call the NetProfit function and assign its outout to a variable named profit_for_report" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "profit_for_report = NetProfit(sales_price, cost_fixed, labor, parts, product_sold)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lastly, we print the value of the variable profit_for_report" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1250000\n" ] } ], "source": [ "print(profit_for_report)" ] } ], "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.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }
Oct 02, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here