"\u001b[1;32m<ipython-input-1-43a14fcd4265>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhello\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mNameError\u001b[0m: name 'hello' is not defined"
]
}
],
"source": [
"print(hello)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<li> You forgot to create a variable before using it\n"
"We are studying inflammation in patients who have been given a new treatment for arthritis, and need to analyze the first dozen data sets of their daily inflammation. The data sets are stored in comma-separated values (CSV) format: each row holds information for a single patient, and the columns represent successive days"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We want to:\n",
"\n",
" * load that data into memory,\n",
" * calculate the average inflammation per day across all patients, and\n",
" * plot the result.\n",
"\n",
"To do all that, we’ll have to learn a little bit about programming."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python as a calculator\n",
"\n",
"Any Python interpreter can be used as a calculator:"
"This only outputs a value. To use values in any manner, we have to access them in memory by using a variable.\n",
"\n",
"In Python, variable names:\n",
"\n",
"* can include letters, digits, and underscores\n",
"* cannot start with a digit\n",
"* are case sensitive.\n",
"\n",
"Let's assign a value 55 to variable named ``weight_kg``:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"weight_kg = 55 # we assign the value 55 to the variable weight_kg using ="
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We use ``print`` to output the value of a variable. Is a built-in function:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"55\n"
]
}
],
"source": [
"print(weight_kg) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can do some arithmetics with variables:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Weight in pounds: 121.00000000000001\n"
]
}
],
"source": [
"print(\"Weight in pounds: \", 2.2 * weight_kg) # Don't forget to explain about printing\n",
" # types, strings and comma separation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What the ...?? why is not simply giving 121.0??? <br>\n",
"(<strong>Pro tip:</strong> <em>Because 2.2 is a number with no exact float representation, so it multiplies by the closest number with a float representation. That produces a 1 at the last decimal position so Python realices that there is something non-zero at the end and plots it.</em>)<br><br>\n",
"Well it looks 121 enought to me.... Ok let's continue. \n",
"\n",
"We can change the value of a variable by re-assigning it:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Weight in kilograms is now: 57.5\n"
]
}
],
"source": [
"weight_kg = 57.5\n",
"print('Weight in kilograms is now:', weight_kg)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Variables as sticky notes with the name put in a particular value.<br>\n",