240615
This commit is contained in:
159
week1/betaversion/C1_W1_Lab01_Python_Jupyter_Soln.ipynb
Normal file
159
week1/betaversion/C1_W1_Lab01_Python_Jupyter_Soln.ipynb
Normal file
@@ -0,0 +1,159 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Optional Lab: Brief Introduction to Python and Jupyter Notebooks\n",
|
||||
"Welcome to the first optional lab! \n",
|
||||
"Optional labs are available to:\n",
|
||||
"- provide information - like this notebook\n",
|
||||
"- reinforce lecture material with hands-on examples\n",
|
||||
"- provide working examples of routines used in the graded labs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Goals\n",
|
||||
"In this lab, you will:\n",
|
||||
"- Get a brief introduction to Jupyter notebooks\n",
|
||||
"- Take a tour of Jupyter notebooks\n",
|
||||
"- Learn the difference between markdown cells and code cells\n",
|
||||
"- Practice some basic python\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The easiest way to become familiar with Jupyter notebooks is to take the tour available above in the Help menu:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<figure>\n",
|
||||
" <center> <img src=\"./images/C1W1L1_Tour.PNG\" alt='missing' width=\"400\" ><center/>\n",
|
||||
"<figure/>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Jupyter notebooks have two types of cells that are used in this course. Cells such as this which contain documentation called `Markdown Cells`. The name is derived from the simple formatting language used in the cells. You will not be required to produce markdown cells. Its useful to understand the `cell pulldown` shown in graphic below. Occasionally, a cell will end up in the wrong mode and you may need to restore it to the right state:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<figure>\n",
|
||||
" <img src=\"./images/C1W1L1_Markdown.PNG\" alt='missing' width=\"400\" >\n",
|
||||
"<figure/>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The other type of cell is the `code cell` where you will write your code:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"This is code cell\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#This is a 'Code' Cell\n",
|
||||
"print(\"This is code cell\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Python\n",
|
||||
"You can write your code in the code cells. \n",
|
||||
"To run the code, select the cell and either\n",
|
||||
"- hold the shift-key down and hit 'enter' or 'return'\n",
|
||||
"- click the 'run' arrow above\n",
|
||||
"<figure>\n",
|
||||
" <img src=\"./images/C1W1L1_Run.PNG\" width=\"400\" >\n",
|
||||
"<figure/>\n",
|
||||
"\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Print statement\n",
|
||||
"Print statements will generally use the python f-string style. \n",
|
||||
"Try creating your own print in the following cell. \n",
|
||||
"Try both methods of running the cell."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"f strings allow you to embed variables right in the strings!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# print statements\n",
|
||||
"variable = \"right in the strings!\"\n",
|
||||
"print(f\"f strings allow you to embed variables {variable}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Congratulations!\n",
|
||||
"You now know how to find your way around a Jupyter Notebook."
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user