{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "plt.style.use('seaborn')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Computing daily energy needs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First factor: your reference energy need.\n", "\n", "See [https://en.wikipedia.org/wiki/Harris–Benedict_equation]." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def energy_need_female(physical_activity, weight_kg, height_cm, age):\n", " return physical_activity * (9.99 * weight_kg + 6.25 * height_cm - 4.92 * age - 161)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def energy_need_male(physical_activity, weight_kg, height_cm, age):\n", " return physical_activity * (9.99 * weight_kg + 6.25 * height_cm - 4.92 * age + 5)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "def print_energy(physical_activity, weight_kg, height_cm, age):\n", " print(\"male: {:.0f} Cal, female: {:.0f} Cal\".format(energy_need_male(physical_activity, weight_kg, height_cm, age),\n", " energy_need_female(physical_activity, weight_kg, height_cm, age)))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import interact" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c16417042f1545f5b670e86fb5a5f1e7", "version_major": 2, "version_minor": 0 }, "text/html": [ "
Failed to display Jupyter Widget of type interactive
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "interactive(children=(FloatSlider(value=1.5999999999999999, description='physical_activity', max=1.8, min=1.4, step=0.01), FloatSlider(value=85.0, description='weight_kg', max=150.0, min=20.0, step=0.5), FloatSlider(value=185.0, description='height_cm', max=220.0, min=150.0, step=0.5), IntSlider(value=58, description='age', max=99, min=18), Output()), _dom_classes=('widget-interact',))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "Failed to display Jupyter Widget of type interactive
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "interactive(children=(Dropdown(description='sex', options=('male', 'female'), value='male'), FloatSlider(value=1.5999999999999999, description='physical_activity', max=1.8, min=1.4, step=0.01), FloatSlider(value=85.0, description='weight_kg', max=150.0, min=20.0, step=0.5), FloatSlider(value=185.0, description='height_cm', max=220.0, min=150.0, step=0.5), IntSlider(value=58, description='age', max=99, min=18), IntSlider(value=0, description='caloric_delta_from_starting_weight', max=2000, min=-2000, step=10), Output()), _dom_classes=('widget-interact',))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "Failed to display Jupyter Widget of type interactive
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "interactive(children=(Dropdown(description='sex', options=('male', 'female'), value='male'), FloatSlider(value=1.5999999999999999, description='physical_activity', max=1.8, min=1.4, step=0.01), FloatSlider(value=85.0, description='weight_kg', max=150.0, min=20.0, step=0.5), FloatSlider(value=185.0, description='height_cm', max=220.0, min=150.0, step=0.5), IntSlider(value=58, description='age', max=99, min=18), IntSlider(value=0, description='caloric_delta_from_starting_weight', max=2000, min=-2000, step=10), Output()), _dom_classes=('widget-interact',))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "