-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d20f5f
commit f2c47a4
Showing
5 changed files
with
1,051 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
layout: post | ||
title: "Virtual lab: Sequences" | ||
tags: sequences | ||
--- | ||
|
||
Today's virtual lab went over the tutorial for the Sequences chapter for [Python | ||
for Mathematics](https://vknight.org/pfm/tools-for-mathematics/07-sequences/tutorial/main.html). | ||
|
||
You can see a recording of the class [here](https://cardiff.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=7746463b-8996-4c71-9b59-b22700bad326). | ||
|
||
You can find the notebook I worked on here [sequences-tutorial.ipynb]({{site.baseurl}}/assets/nbs/2024-2025/sequences-tutorial.ipynb). | ||
|
||
You can also find the board I wrote on when talking about [the Collatz conjecture](https://en.wikipedia.org/wiki/Collatz_conjecture) here [collatz]({{site.baseurl}}/assets/boards/2024-2025/collatz.ipynb) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6b385490-e3ac-45b6-b7e1-1cd71cc5a3b8", | ||
"metadata": {}, | ||
"source": [ | ||
"## Question 4 from probability chapter" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "f91543c8-a6f2-4911-a417-a9c997a61815", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import random\n", | ||
"\n", | ||
"def sample_experiment():\n", | ||
" \"\"\"\n", | ||
" Sample a travel method and whether or not we are late\n", | ||
" \"\"\"\n", | ||
" random_number = random.random()\n", | ||
" if random_number < 1 / 2:\n", | ||
" travel_method = \"car\"\n", | ||
" probability_of_late = 1 / 5\n", | ||
" elif random_number < 1 / 2 + 1 / 6:\n", | ||
" travel_method = \"bike\"\n", | ||
" probability_of_late = 2 / 5\n", | ||
" else:\n", | ||
" travel_method = \"foot\"\n", | ||
" probability_of_late = 1 / 10\n", | ||
" return travel_method, random.random() < probability_of_late" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "839b73a0-8d10-4446-9edc-bc491d461efa", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import random\n", | ||
"\n", | ||
"def sample_experiment():\n", | ||
" \"\"\"\n", | ||
" Sample a travel method and whether or not we are late\n", | ||
" \"\"\"\n", | ||
" random_number = random.random()\n", | ||
" \n", | ||
" if random_number < 1 / 2:\n", | ||
" travel_method = \"car\"\n", | ||
" is_late = random.random() < 1 / 5\n", | ||
" return travel_method, is_late\n", | ||
" \n", | ||
" if random_number < 1 / 2 + 1 / 6:\n", | ||
" travel_method = \"bike\"\n", | ||
" is_late = random.random() < 2 / 5\n", | ||
" return travel_method, is_late\n", | ||
"\n", | ||
" travel_method = \"foot\"\n", | ||
" is_late = random.random() < 1 / 10\n", | ||
" return travel_method, is_late" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "91c27fee-58e4-4515-98f4-86b40c53dbb6", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"81.91554102604361" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"random.random() * 1/5" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "6ce5e629-5c6f-4c7c-bb9e-b98cf8a8c697", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"\u001b[0;31mSignature:\u001b[0m \u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;31mDocstring:\u001b[0m\n", | ||
"Return random integer in range [a, b], including both end points.\n", | ||
" \n", | ||
"\u001b[0;31mFile:\u001b[0m /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/random.py\n", | ||
"\u001b[0;31mType:\u001b[0m method" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"random.randint?" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "6c802fd8-0091-4f3d-9b2b-5e3a4b6f28a6", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'Riggins'" | ||
] | ||
}, | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"random.choice((\"Julien\", \"Kaitlynn\", \"Riggins\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "126e9a9d-d2b5-4abb-b245-e51007841e75", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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.13.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.