Skip to content

Commit

Permalink
Patrick notebook (#43)
Browse files Browse the repository at this point in the history
Great, thanks! I'm going to merge and any issues we have can be dealt with separately.

Issues #11 #16
  • Loading branch information
OmegaLambda1998 authored Feb 14, 2020
1 parent ce7b556 commit 2b4cf2d
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 3 deletions.
182 changes: 182 additions & 0 deletions python/01. Variables.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,187 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 01. Variables\n",
"\n",
"`Variables` are a way of storing information in python. They work by assigning a `name` to a `value`"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PANOPTES\n"
]
}
],
"source": [
"var = \"PANOPTES\"\n",
"print(var)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"------------\n",
" name\n",
"\n",
"\n",
"```python\n",
"var = \"PANOPTES\"\n",
"```\n",
"\n",
"\n",
" \n",
" value\n",
"\n",
"------------\n",
"\n",
"Because we created this variable, when we run:\n",
"```python\n",
"print(var)\n",
"```\n",
"\n",
"we print `\"PANOPTES\"` instead of `var`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 1\n",
"\n",
"In the following cell:\n",
"\n",
"1. Create a variable called `my_name` that stores your name\n",
"2. Create a variable called `my_age` that stores your age\n",
"3. Create a variable called `my_home` that stores your home address\n",
"\n",
"If you try to run the cell before you make these variables (or if you call them the wrong thing) you will get an `Error`. You can learn more about these in [Errors](12.%20Errors.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, my name is Patrick Armstrong, I am 21 years old, and I live at 21a Braggett St. Gungahlin\n"
]
}
],
"source": [
"# First create a variable called my_name\n",
"\n",
"# Then create a variable called my_age\n",
"\n",
"# Then create a variable called my_home\n",
"\n",
"print(f\"Hello, my name is {my_name}, I am {my_age} years old, and I live at {my_home}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the final print statement, we did something fancy to put your variables into the `String`. You can learn more about this in the next notebook [Data Types](02.%20Data%20Types.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are a few rules when it comes to naming python variables. Some of these are hard rules that *must* be followed, and others are conventions that make it easier for other people to read your code.\n",
"\n",
"### Hard rules\n",
"1. Your variable name *must* begin with a letter (a - z, A - Z) or an underscore (_)\n",
"2. All characters after the first *must* be either letters, numbers or underscores\n",
"3. Variable names are case sensitive (so `variable`, `Variable`, and `VARIABLE` are all different)\n",
"4. It can be any length (although shouldn't be too long)\n",
"5. There are some words you can't use because python already uses them. A full list is available [here](https://www.tutorialspoint.com/What-are-Reserved-Keywords-in-Python)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 2\n",
"If you run the following cell, you will get some `errors`. Change the variable names so that the code runs."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-11-8d59e7e6e3d7>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-11-8d59e7e6e3d7>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m $dollars = 42\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"$dollars = 42\n",
"is_black_&_white = False\n",
"my name = \"PANOPTES\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Best practice / Guidlines\n",
"1. Names should be meaningfull and descriptive. For instance `num_of_points` is better than `nop`\n",
"2. Names should not be too long. For instance `num_of_points` is better than `the_number_of_points_needed_for_the_calculation`\n",
"3. Names should be consistent. Either write things out like `num_of_points` ***or*** `numOfPoints`, not both!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge 3\n",
"\n",
"Try to rename the variables in the following cell so they follow these guidelines. Afterward, show it to your mentor (or compare it to the answer notebook) to see how you did."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# The background colour\n",
"the_colour_of_the_background = \"red\"\n",
"\n",
"# The text colour\n",
"c = \"blue\"\n",
"\n",
"# The foreground colour\n",
"foregroundColour = \"green\" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Congratulations! You've finished the variables notebook. The next notebook is [Data Types](02.%20Data%20Types.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
6 changes: 3 additions & 3 deletions python/02. Data Types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"An empty list, as shown above, is also valid! You can define empty lists and add to them later. You can read more about lists [here](https://github.com/panoptes/panoptes-tutorials/blob/master/python/04.%20Lists.ipynb)."
"An empty list, as shown above, is also valid! You can define empty lists and add to them later. You can read more about lists [here](04.%20Lists.ipynb)."
]
},
{
Expand Down Expand Up @@ -339,7 +339,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For more on dictionaries, see our dictionaries tutorial [here](https://github.com/panoptes/panoptes-tutorials/blob/master/python/05.%20Dictionaries.ipynb)."
"For more on dictionaries, see our dictionaries tutorial [here](05.%20Dictionaries.ipynb)."
]
},
{
Expand Down Expand Up @@ -479,7 +479,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.6.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 2b4cf2d

Please sign in to comment.