Skip to content

Commit

Permalink
Merge pull request #62 from GWC-DCMB/james_lesson_practice_edit
Browse files Browse the repository at this point in the history
lesson/practice 10-19 notebook edit
  • Loading branch information
echou89 authored Mar 7, 2024
2 parents eca2778 + 7ff2d00 commit cee3fe7
Show file tree
Hide file tree
Showing 30 changed files with 3,151 additions and 2,298 deletions.
2 changes: 1 addition & 1 deletion Lessons/Lesson10_Loops1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"id": "KaIbwdt75atI"
},
"source": [
"We don't just have to use range, though. Let's say we only wanted to print out some of the animals in our list. We could give our for loop a list of indices in our list we wanted to print"
"We don't just have to use range, though. Let's say we only want to print out some of the animals in our list. We could give our for loop a list of indices in our list we want to print."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion Lessons/Lesson11_Loops2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"id": "d0M15gC77cjX"
},
"source": [
"Another keyword that is useful for controlling your for loop is `break`. If you want your for loop to stop running after a certain condition is true, you can use `break`. Once `break` is called, the foor loop stops\u2014no other code runs for the current item, and the for loop won't continue to the rest of the items in the list."
"Another keyword that is useful for controlling your for loop is `break`. If you want your for loop to stop running after a certain condition is true, you can use `break`. Once `break` is called, the for loop stops — no other code runs for the current item, and the for loop won't continue to the rest of the items in the list."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion Lessons/Lesson12_Functions_and_Methods.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"id": "hX1FOn-H911e"
},
"source": [
"Nice! It's a list, just like we expected. What do you think the type is of the first element in `numbers`?"
"Nice! It's a list, just like we expected. What is the type of the first element in `numbers`?"
]
},
{
Expand Down
188 changes: 94 additions & 94 deletions Lessons/Lesson13_Packages.ipynb
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"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.3"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "W-MLnYHC95MA",
"colab_type": "text"
"colab_type": "text",
"id": "W-MLnYHC95MA"
},
"source": [
"# Packages\n",
Expand All @@ -36,7 +15,7 @@
"- **Methods** can only be used on one specific type of object. For example, append can only be used on lists (and not strings or numbers).\n",
"- The input to **functions** goes *between* parentheses after the name of function\n",
" - Example: `print(print_input)` \n",
" At least part of the input to **methods** comes *before* the name of the method and is followed by a period (`.`)\n",
"- At least part of the input to **methods** comes *before* the name of the method and is followed by a period (`.`)\n",
" - Example: `mylist.append(what_to_append)`\n",
" \n",
"Python comes with certain built-in functions and methods like the ones we used in the previous section (such as `print` and `append`). But sometimes you might want to do things that are a bit more complicated. For this, you can import **packages**. \n",
Expand All @@ -46,174 +25,174 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ewWUGvuj95MB",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "ewWUGvuj95MB"
},
"outputs": [],
"source": [
"# list of numbers\n",
"numbers = [10,2.3,-4,20,14,1,2,0,-3,1,-2,2,2,65.4,3,-23,123,43.1,32,57,32]\n",
"\n",
"# print numbers\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Es4gFBPv95ME",
"colab_type": "text"
"colab_type": "text",
"id": "Es4gFBPv95ME"
},
"source": [
"Packages are groups of functions and methods that you can **`import`** and then use just like built-in functions and packages.\n",
"Packages are groups of functions and methods that you can **`import`** and then use just like built-in functions and methods.\n",
"\n",
"One example of a very powerful packages is **`numpy`**. To import numpy and load all of the functions in that packages into your environmnent (in this Jupyter Notebook), you do this:"
"One example of a very powerful package is **`numpy`**. To import **`numpy`** and load all of the functions in that packages into your environmnent (in this Jupyter Notebook), you do the following:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "rObaFmRn95MF",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "rObaFmRn95MF"
},
"outputs": [],
"source": [
"# import numpy package\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BDlGTHNz95MJ",
"colab_type": "text"
"colab_type": "text",
"id": "BDlGTHNz95MJ"
},
"source": [
"Then you can use functions in this package. One function is the `mean` function to find the mean of a list of numbers. To do this, you have to use the prefix numpy so Python knows that the function comes from the numpy package:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "kDimXsB795MK",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "kDimXsB795MK"
},
"outputs": [],
"source": [
"# get the mean of numbers using the numpy mean function\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "U2q43aFm95MN",
"colab_type": "text"
"colab_type": "text",
"id": "U2q43aFm95MN"
},
"source": [
"Nice, it's the same as we got before when we calculated the mean ourselves!\n",
"\n",
"Typing out numpy every time is a lot of work, so a lot of people like to shorten the prefix you have to use. If you want the prefix to be `np` instead of `numpy`, you can import the package as follows:"
"Typing out `numpy` every time is a lot of work, so a lot of people like to shorten the prefix you have to use. If you want the prefix to be `np` instead of `numpy`, you can import the package as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "LWQKGxYz95MO",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "LWQKGxYz95MO"
},
"outputs": [],
"source": [
"# import numpy package as np\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3O-acSyl95MR",
"colab_type": "text"
"colab_type": "text",
"id": "3O-acSyl95MR"
},
"source": [
"Now, if you want to find the mean of numbers using the numpy mean function, you just have to use the prefix `np`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "aP1Q5pKz95MR",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "aP1Q5pKz95MR"
},
"outputs": [],
"source": [
"# print the mean of numbers\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "-bDcIF8u95MU",
"colab_type": "text"
"colab_type": "text",
"id": "-bDcIF8u95MU"
},
"source": [
"Let's explore some other functions in the numpy package.\n",
"\n",
"Before, we learned how to find the absolute value of a number using the `abs` function. If we want to get the absolute value of everything in a list, we can use the numpy absolute value function:"
"Before, we learned how to find the absolute value of a number using the `abs` function. If we want to get the absolute value of everything in a list, we can use the `numpy` absolute value function:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "NL8TYvru95MV",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "NL8TYvru95MV"
},
"outputs": [],
"source": [
"# get absolute value of all numbers in numbers and save it to the variable abs_nums\n",
"\n",
"# print abs_nums\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "pB8q-jnZ95MY",
"colab_type": "text"
"colab_type": "text",
"id": "pB8q-jnZ95MY"
},
"source": [
"Did you notice that this looks different than a list? Let's look at the type of abs_nums:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "947SMIX395MZ",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "947SMIX395MZ"
},
"outputs": [],
"source": [
"# get the type of abs_nums\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "GWJ5HH1E95Md",
"colab_type": "text"
"colab_type": "text",
"id": "GWJ5HH1E95Md"
},
"source": [
"It's a numpy.ndarray. You'll learn more about what that means in a future lesson!\n",
"It's a `numpy.ndarray`. You'll learn more about what that means in a future lesson!\n",
"\n",
"Numpy has a similar function for `round`.\n",
"\n",
Expand All @@ -222,61 +201,82 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "hWl4qhXy95Me",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "hWl4qhXy95Me"
},
"outputs": [],
"source": [
"# print numbers\n",
"\n",
"# sort numbers\n",
"\n",
"# print numbers\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "GG4mHnga95Mh",
"colab_type": "text"
"colab_type": "text",
"id": "GG4mHnga95Mh"
},
"source": [
"Now let's try it on the abs_nums list:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2Hx09GK495Mj",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "2Hx09GK495Mj"
},
"outputs": [],
"source": [
"# print abs_nums\n",
"\n",
"# sort abs_nums\n",
"\n",
"# print abs_nums\n"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "36EF3Kfy95Mm",
"colab_type": "text"
"colab_type": "text",
"id": "36EF3Kfy95Mm"
},
"source": [
"Nice job! You just learned about packages in Python! You learned:\n",
"- How to import new functions in packages in Python\n",
"- More functions and methods\n",
"\n",
"You'll learn more about numpy in a future lesson. There are also tons of other packages out there for different purposes. We'll learn about the `pandas` package in the next lesson, and the `matplotlib` package in a few days!"
"You'll learn more about `numpy` in a future lesson. There are also tons of other packages out there for different purposes. We'll learn about the `pandas` package in the next lesson, and the `matplotlib` package in a few days!"
]
}
]
],
"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.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit cee3fe7

Please sign in to comment.