Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
avhsu authored Nov 11, 2024
1 parent 9b5aeb3 commit bd32f7f
Show file tree
Hide file tree
Showing 2 changed files with 207 additions and 30 deletions.
72 changes: 45 additions & 27 deletions notebooks-2024-update/00-Background-Information.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Strong institutional suport from\n",
"## Strong instututional support from...\n",
"* UK Met Office\n",
"* British Atmospheric Data Centre (BADC)\n",
"* Cefas\n",
Expand Down Expand Up @@ -139,38 +139,49 @@
"source": [
"## Jupyter Notebooks\n",
"\n",
"- You are currently in a Jupyter notebook!\n",
"- A notebook is a series of **cells**.\n",
"- The active cell (the one you are currently using) has an outline around it.\n",
"- You can navigate to different cells with the arrow keys.\n",
"- A cell can be either be code, markdown, or \"raw\":\n",
"\n",
" - Code\n",
" - Python\n",
" - R\n",
" - Julia\n",
" - [Many Others](https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages)\n",
" \n",
" - Markdown cells contain plain text\n",
" - to add a heading to a markdown cell, use #\n",
" \n",
" - Raw cells are for converting to different formats\n",
" - we wont be using these here. [more info](https://nbsphinx.readthedocs.io/en/0.3.1/raw-cells.html)\n",
" \n",
"- Create cells from the Notebook menu or using keyboard shortcuts.\n",
" - `h`: Bring up keyboard shortcuts screen.\n",
" - `b` Make a new cell below the current cell\n",
" - `dd` delete current cell\n",
" - `Enter` To enter edit mode for the current cell (or double click it)\n",
" - `Ctrl`-`Enter` Run the current cell\n",
" - `Esc` Exit edit mode\n",
" - `Ctrl`-`s`: Save Notebook"
" - You can run the code in individual cells at a time.\n",
" - The active cell (the one you are currently using) has an outline around it.\n",
" - You can navigate to different cells with the arrow keys.\n",
"A cell can be either be **code**, **Markdown**, or **raw**:\n",
"- **Code**\n",
" - any code that you write and run will be in a \"code\" cell\n",
" - To **run the code** in a cell, press `Ctrl-Enter` or `Shift-Enter` (or you can press Run at the toolbar at the top!)\n",
" - To **create a cell**, press the `+` in the toolbar at the top.\n",
" - To **comment** out multiple lines of code, press `Ctrl-/` for Windows or `Command-/` for Mac.\n",
"- **Markdown**\n",
" - contain plain text, generally used for describing and organizing the code (or in this case, for teaching!)\n",
" - e.g., to add a heading to a markdown cell, use #\n",
"- **Raw**\n",
" - We wont be using these here. [more info](https://nbsphinx.readthedocs.io/en/0.3.1/raw-cells.html)\n",
" - Used for converting to different formats"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can write code in **different languages** in a Jupyter notebook.\n",
"- Python\n",
"- R\n",
"- Julia\n",
"- [Many Others](https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages)\n",
" \n",
"There are a number of **keyboard shortcuts** you can use to edit your notebook. They are actually written in the toolbar itself, so no need to memorize them!\n",
"- `h`: Bring up keyboard shortcuts screen.\n",
"- `b` Make a new cell below the current cell\n",
"- `dd` delete current cell\n",
"- `Enter` To enter edit mode for the current cell (or double click it)\n",
"- `Esc` Exit edit mode\n",
"- `Ctrl`-`s`: Save Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Other features\n",
"### Other features\n",
"- tab autocompletion, start typing something and hit tab for suggestions\n",
"- inline documentation, type a command name followed by a question mark `open?`\n",
"- run shell commands e.g., `ls`\n",
Expand All @@ -187,6 +198,13 @@
"ls"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Other IDEs you can write Python in:"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -200,7 +218,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you have **Python** installed on your computer through **anaconda** you can run python code in **Jupyter Notebooks**, **spyder, Pycharm** or straight from the command line as you prefer. Experiment with different code editors and find a setup that works for you :)"
"Once you have **Python** installed on your computer through **Anaconda** you can run python code in **Jupyter Notebooks**, **spyder, Pycharm** or straight from the command line as you prefer. Experiment with different code editors and find a setup that works for you :)"
]
},
{
Expand Down
165 changes: 162 additions & 3 deletions notebooks-2024-update/01-Introduction-to-Python-ALICE.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### A link to the worksheet corresponding to this notebook can be found *[here](https://docs.google.com/document/d/1VhkS4cKEBcvHQZMc8jodwdXXRx0VOeBJiVcAc-YDYJg/edit?usp=sharing).*"
"### A link to the worksheet corresponding to this notebook can be found *[here](https://docs.google.com/document/d/1VhkS4cKEBcvHQZMc8jodwdXXRx0VOeBJiVcAc-YDYJg/edit?usp=sharing).*\n",
"\n",
"This notebook and worksheet were developed by Alice Hsu for UEA Python PPDs 2024. Last updated: 14/11/2024."
]
},
{
Expand Down Expand Up @@ -43,7 +45,8 @@
" <li>While loops</li>\n",
" </ol>\n",
" </ol>\n",
"5. **Coding Challenges**"
"5. **Coding Challenges**\n",
"5. **Functions**"
]
},
{
Expand Down Expand Up @@ -1544,7 +1547,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1851,6 +1854,13 @@
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1896,6 +1906,13 @@
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1943,6 +1960,148 @@
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Functions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Functions** generally take inputs (called **parameters**) and return one or more outputs. Functions are useful because they are reusable - you can run the same code on different variables without having to rewrite all the code every time.\n",
"\n",
"Some examples of some functions:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def f(x):\n",
" y = x+1\n",
" return y"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def g(x,y):\n",
" z = x**2+**2\n",
" return z"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note the syntax for defining a function.\n",
"\n",
"* You must use the `def` keyword, followed by your **function name**, the **inputs** you would like to use in **parentheses**, and followed by a **colon**.\n",
"* The operations that you perform within your function must be **indented to the right of the `def` line** with your function name and inputs.\n",
"* You must **specify the outputs** you would like your function to compute using the **return** keyword."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### WKSH EX15\n",
"\n",
"Complete the exercises in the worksheet and then run the cell below to check your answers."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def add_max(list1,list2):\n",
"\n",
" list1_max = max(list1)\n",
" list2_max = max(list2)\n",
"\n",
" list1_2_max = list1_max + list2_max\n",
"\n",
" return list1_2_max"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### WKSH EX16\n",
"\n",
"**(A)** Write a function called parabola that takes an input `x` and outputs a point on the `parabola` y = x$^2$+2x+1."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**(B)** Write a function called `circles` that takes a radius of a circle as input and returns\n",
"* the circumference\n",
"* the area of that circle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### iPYNB EX9\n",
"\n",
"In iPYNB EX8, you wrote a sequence of `if-elif` statements that outputs a student’s grade based on their score in the table below.\n",
"\n",
"|A|B|C|D|F|\n",
"|:-:|:-:|:-:|:-:|:-:|\n",
"|90 ≥ grade|80 ≤ grade < 90|70 ≤ grade < 80|60 ≤ grade < 70|grade < 60|\n",
"\n",
"Using your code from this exercise, create a function called `my_grade()` that takes `score` as an input and outputs the grade as a string (e.g., `'A'`)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit bd32f7f

Please sign in to comment.