Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Lectures and Reference #3

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions hw/hw01/hw01.ipynb

Large diffs are not rendered by default.

93 changes: 90 additions & 3 deletions hw/hw02/hw02.ipynb

Large diffs are not rendered by default.

92 changes: 90 additions & 2 deletions hw/hw03/hw03.ipynb

Large diffs are not rendered by default.

59 changes: 57 additions & 2 deletions hw/hw04/hw04.ipynb

Large diffs are not rendered by default.

39 changes: 37 additions & 2 deletions hw/hw05/hw05.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-0",
"metadata": {
"deletable": false,
"editable": false
},
"outputs": [],
"source": [
"# The pip install can take a minute\n",
"%pip install -q urllib3<2.0 otter-grader==4.3.4 datascience ipywidgets\n",
"%pip install -q urllib3<2.0 otter-grader==4.4.1 datascience ipywidgets\n",
"import pyodide_http\n",
"pyodide_http.patch_all()\n",
"\n",
Expand All @@ -21,6 +22,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-1",
"metadata": {},
"source": [
"# Homework 5: Applying Functions and Iteration\n",
Expand All @@ -30,6 +32,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-2",
"metadata": {},
"source": [
"**Helpful Resource:**\n",
Expand All @@ -45,6 +48,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-3",
"metadata": {},
"source": [
"Please complete this notebook by filling in the cells provided. Before you begin, execute the following cell to setup the notebook by importing some helpful libraries. Each time you start your server, you will need to execute this cell again.\n",
Expand All @@ -62,6 +66,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-4",
"metadata": {},
"source": [
"## 1. 2021 Cal Football Season"
Expand All @@ -70,6 +75,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-5",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -78,13 +84,13 @@
"# These lines import the numpy and datascience modules.\n",
"import numpy as np\n",
"from datascience import *\n",
"\n",
"import warnings\n",
"warnings.simplefilter('ignore', FutureWarning)"
]
},
{
"cell_type": "markdown",
"id": "cell-hw05-6",
"metadata": {},
"source": [
"James is trying to analyze how well the Cal football team performed in the 2021 season. A football game is divided into four periods, called quarters. The number of points Cal scored in each quarter and the number of points their opponent scored in each quarter are stored in a table called `https://ds-modules.github.io/materials-sp22-assets/hw/hw05/cal_fb.csv`."
Expand All @@ -93,6 +99,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-7",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -107,6 +114,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-8",
"metadata": {},
"source": [
"Let's start by finding the total points each team scored in a game.\n",
Expand All @@ -120,6 +128,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-9",
"metadata": {
"tags": []
},
Expand All @@ -135,6 +144,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-10",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -146,6 +156,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-11",
"metadata": {},
"source": [
"**Question 2.** Create a new table `final_scores` with three columns in this *specific* order: `Opponent`, `Cal Score`, `Opponent Score`. You will have to create the `Cal Score` and `Opponent Score` columns. Use the function `sum_scores` you just defined in the previous question for this problem. **(20 Points)**\n",
Expand All @@ -158,6 +169,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-12",
"metadata": {
"tags": []
},
Expand All @@ -172,6 +184,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-13",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -183,6 +196,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-14",
"metadata": {},
"source": [
"We can get specific row objects from a table. You can use `tbl.row(n)` to get the `n`th row of a table. `row.item(\"column_name\")` will allow you to select the element that corresponds to `column_name` in a particular row. Here's an example:"
Expand All @@ -191,6 +205,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-15",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -205,6 +220,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-16",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -217,6 +233,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-17",
"metadata": {},
"source": [
"**Question 3.** We want to see for a particular game whether or not Cal lost. Write a function called `did_cal_lose`. It should take one argument: a **row object** from the `final_scores` table. It should return either `True` if Cal's score was less than the Opponent's score, and `False` otherwise. **(20 Points)**\n",
Expand All @@ -229,6 +246,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-18",
"metadata": {
"tags": []
},
Expand All @@ -243,6 +261,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-19",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -254,6 +273,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-20",
"metadata": {},
"source": [
"**Question 4.** James wants to see how Cal did against every opponent during the 2021 season. Using the `final_scores` table:\n",
Expand All @@ -275,6 +295,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-21",
"metadata": {
"tags": []
},
Expand All @@ -292,6 +313,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-22",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -303,6 +325,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-23",
"metadata": {},
"source": [
"**Question 5:** Sometimes in football the two teams are equally matched and the game is quite close. Other times, it is a blowout, where the winning team wins by a large margin of victory. Let's define a **big win** to be a game in which the winning team won by more than 10 points.\n",
Expand All @@ -313,6 +336,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-24",
"metadata": {
"tags": []
},
Expand All @@ -339,6 +363,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-25",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -350,6 +375,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-26",
"metadata": {},
"source": [
"You're done with the required section of Homework 5! Continue on to the optional section for some more practice with iterations and for loops.\n",
Expand All @@ -359,13 +385,15 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-27",
"metadata": {},
"source": [
"## 2. Unrolling Loops (Optional)"
]
},
{
"cell_type": "markdown",
"id": "cell-hw05-28",
"metadata": {},
"source": [
"**This section of HW5 is optional. Do it for your own practice, but it will not be incorporated into the final grading!**\n",
Expand All @@ -390,6 +418,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-29",
"metadata": {},
"source": [
"**Optional Question 1.** Unroll the code below."
Expand All @@ -398,6 +427,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-30",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -416,6 +446,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-31",
"metadata": {
"for_assignment_type": "solution",
"tags": []
Expand All @@ -427,6 +458,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-32",
"metadata": {},
"source": [
"Congratulations, you are done with Homework 5!\n",
Expand All @@ -442,6 +474,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-33",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -455,6 +488,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cell-hw05-34",
"metadata": {
"deletable": false,
"editable": false
Expand All @@ -467,6 +501,7 @@
},
{
"cell_type": "markdown",
"id": "cell-hw05-35",
"metadata": {},
"source": [
" "
Expand Down
Loading
Loading