diff --git a/_toc.yml b/_toc.yml index 8a1d857..8c8eb10 100755 --- a/_toc.yml +++ b/_toc.yml @@ -11,169 +11,17 @@ parts: # - file: about/doing_well # - file: about/faq -# - caption: Getting Started -# chapters: -# - file: getting-started/pre_term -# - file: getting-started/tasks1 -# - file: getting-started/tasks2 -# - file: getting-started/tasks3 -# - file: notes/setup/stack -# title: Setup Your Machine -# sections: -# - file: notes/setup/install_macOS -# - file: notes/setup/install_windows - # - file: notes/setup/install_ubuntu +- caption: Part 1 - Getting Started + maxdepth: 1 + chapters: + - file: notes/part01/workshop01 + title: Workshop 1 + - file: notes/part01/lab01A + - file: notes/part01/lab01B -# - caption: Demo section -# chapters: -# - file: notes/demo01/demo01_summary -# title: Demo 1 - Data Science -# sections: -# - file: notes/demo01/lecture1 -# - file: notes/demo01/lecture2 -# - file: notes/demo01/lecture3 -# - file: notes/demo02/demo02_summary -# title: Demo 2 - Introductory Physics -# sections: -# - file: notes/demo02/videos -# - file: notes/demo02/homework -# - file: notes/demo02/readings -# - file: notes/demo02/lab -# - file: notes/demo02/learninglogs -# - file: notes/demo02/test -# - file: notes/demo03/demo03_summary -# title: Demo 3 - Shakespeare -# - file: notes/demo04/demo04_summary -# title: Demo 4 - Chemistry -# - url: https://firas.moosvi.com/books/active-learning-technologies/jupyterdays/capacitor_talk/Capacitor.html -# title: Capacitor Lecture -# - caption: Part 1 - Introductions -# maxdepth: 1 -# chapters: -# - file: notes/week01/week01_summary -# title: Week 1 - Introductions! -# sections: -# - file: notes/week01/class1A -# - file: notes/week01/class1B -# - file: notes/week02/week02_summary -# title: Week 2 - Python Review -# sections: -# - file: notes/week02/videos -# - file: notes/week02/class2A -# - file: notes/week02/class2B -# - file: notes/week02/homework -# - file: notes/week02/lecture -# - file: notes/week02/test -# - file: notes/week02/lab -# - file: notes/week02/learninglogs -# - caption: Part 2 - Dataclass in Python -# chapters: -# - file: notes/week03/week03_summary -# title: Week 3 - Efficiency and Dataclass -# sections: -# # - file: notes/week03/readings -# - file: notes/week03/videos -# - file: notes/week03/class3A -# - file: notes/week03/class3B -# - file: notes/week03/homework -# - file: notes/week03/lecture -# - file: notes/week03/test -# - file: notes/week03/lab -# - file: notes/week03/learninglogs - # - file: notes/week04/week04_summary - # title: Week 4 - Dataclass cont'd - # sections: - # - file: notes/week04/readings - # - file: notes/week04/videos - # - file: notes/week04/class4A - # - file: notes/week04/class4B -# - file: notes/week04/homework -# - file: notes/week04/lecture -# - file: notes/week04/test -# - file: notes/week04/lab -# - file: notes/week04/learninglogs -# - caption: Part 3 - Working with Data -# chapters: -# - file: notes/week05/week05_summary -# title: Week 5 - Web Scraping -# sections: -# - file: notes/week05/videos -# - file: notes/week05/class5A -# - file: notes/week05/class5B -# - file: notes/week05/readings -# - file: notes/week05/homework -# - file: notes/week05/lecture -# - file: notes/week05/test -# - file: notes/week05/lab -# - file: notes/week05/learninglogs -# - file: notes/week06/week06_summary -# title: Week 6 - Git and Version Control -# sections: -# - file: notes/week06/videos -# - file: notes/week06/class6A -# - file: notes/week06/class6B -# - file: notes/week07/week07_summary -# title: Week 7 - Reading week! -# - caption: Part 4 - Algorithms and Data Structures -# chapters: -# - file: notes/week08/week08_summary -# title: Week 8 - Data Structures -# sections: -# - file: notes/week08/videos -# - file: notes/week08/class8A -# - file: notes/week08/class8B -# - file: notes/week09/week09_summary -# title: Week 9 - Graphs -# sections: -# - file: notes/week09/videos -# - file: notes/week09/class9A -# - file: notes/week09/class9B -# - file: notes/week11/week11_summary -# title: Week 11 - MHall -# sections: -# - file: notes/week11/videos -# - file: notes/week11/class11A -# - file: notes/week11/class11B -# - file: notes/week12/week12_summary -# title: Week 12 - State Spaces -# sections: -# - file: notes/week12/videos -# - file: notes/week12/class12A -# - file: notes/week12/class12B -# - file: notes/week13/week13_summary -# title: Week 13 - Maps -# sections: -# - file: notes/week13/videos -# - file: notes/week13/class13A -# - file: notes/week13/class13B -# - file: notes/week14/week14_summary -# title: Week 14 - Natural Language Processing (Optional) -# sections: -# - file: notes/week14/class14A - # - file: notes/week14/class14B - # - file: notes/week14/videos -# - caption: Week 13 - Exam Review -# chapters: -# - file: notes/week13/week13_summary -# title: Week 13 - Review -# sections: -# - file: notes/week13/readings -# - file: notes/week13/videos -# - file: notes/week13/homework -# - file: notes/week13/lecture -# - file: notes/week13/test -# - file: notes/week13/lab -# - file: notes/week13/learninglogs -# - caption: Final Exam -# chapters: -# - file: notes/final -# - caption: Lab Materials -# chapters: -# - file: notes/labs -# title: Lab Stuff - caption: Course Feedback chapters: - file: about/feedback diff --git a/notes/demo01/demo01_summary.md b/notes/demo01/demo01_summary.md deleted file mode 100755 index a726ec2..0000000 --- a/notes/demo01/demo01_summary.md +++ /dev/null @@ -1,20 +0,0 @@ -(page_topic1_demo)= -Week 1 -======================= - -This week we will be doing course introductions, I will be showing you how to navigate the course website, and how the course is set up. -In terms of content, we will use this week to do a math diagnostic, get everyone access to the textbook and homework system, and understand the syllabus. - -## Course Introductions! - -Hello, my name is Firas Moosvi and I am your instructor for Physics 111! - -## Navigating the course website - -Live demo... - -## Navigating Mastering Physics - -```{tip} -I have added an assignment called "Introduction to Mastering Physics" to help familiarize you with the interface. It is due, but there are no marks associated with it. -``` \ No newline at end of file diff --git a/notes/demo01/lecture1.ipynb b/notes/demo01/lecture1.ipynb deleted file mode 100644 index e6619d2..0000000 --- a/notes/demo01/lecture1.ipynb +++ /dev/null @@ -1,3478 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Introduction to Python" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In this class, we will watch the first of four lectures by Dr. Mike Gelbart, option co-director of the UBC-Vancouver MDS program." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Attribution\n", - "\n", - "- The original version of these Python lectures were by [Patrick Walls](https://www.math.ubc.ca/~pwalls/).\n", - "- These lectures were delivered by [Mike Gelbart](https://mikegelbart.com) and are [available publicly here](https://www.youtube.com/watch?v=yBAYduexjuA)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## About this course (5 min)\n", - "\n", - "### High-level overview:\n", - "\n", - "- The MDS program has a programming prerequisite.\n", - "- Therefore, this course does not start from \"no programming knowledge\".\n", - " - You should know what an `if` statement is.\n", - " - You should know what a `for` loop is.\n", - " - You should know what a function is.\n", - "- However, not all of you have used Python/R.\n", - "- So, this course is about _Python-specific_ and _R-specific_ syntax/knowledge.\n", - "- We will cover things like loops, but just the syntax, not the concept of a loop.\n", - "- Weeks 1&2: Python, lectures by Mike Gelbart\n", - "- Weeks 3&4: R, lectures by Tiffany Timbers" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Lecture Outline:\n", - "\n", - "- Basic datatypes (20 min)\n", - "- Lists and tuples (20 min)\n", - "- Break (5 min)\n", - "- String methods (5 min)\n", - "- Dictionaries (10 min)\n", - "- Conditionals (10 min)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Basic datatypes (20 min)\n", - "\n", - "- A **value** is a piece of data that a computer program works with such as a number or text. \n", - "- There are different **types** of values: `42` is an integer and `\"Hello!\"` is a string. \n", - "- A **variable** is a name that refers to a value. \n", - " - In mathematics and statistics, we usually use variables names like $x$ and $y$. \n", - " - In Python, we can use any word as a variable name (as long as it starts with a letter and is not a [reserved word](https://docs.python.org/3.3/reference/lexical_analysis.html#keywords) in Python such as `for`, `while`, `class`, `lambda`, etc.). \n", - "- And we use the **assignment operator** `=` to assign a value to a variable.\n", - "\n", - "See the [Python 3 documentation](https://docs.python.org/3/library/stdtypes.html) for a summary of the standard built-in Python datatypes. See [Think Python (Chapter 2)](http://greenteapress.com/thinkpython/html/thinkpython003.html) for a discussion of variables, expressions and statements in Python." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Common built-in Python data types\n", - "\n", - "| English name | Type name | Description | Example |\n", - "| :--- | :--- | :--- | :--- |\n", - "| integer | `int` | positive/negative whole numbers | `42` |\n", - "| floating point number | `float` | real number in decimal form | `3.14159` |\n", - "| boolean | `bool` | true or false | `True` |\n", - "| string | `str` | text | `\"I Can Has Cheezburger?\"` |\n", - "| list | `list` | a collection of objects - mutable & ordered | `['Ali','Xinyi','Miriam']` |\n", - "| tuple | `tuple` | a collection of objects - immutable & ordered | `('Thursday',6,9,2018)` |\n", - "| dictionary | `dict` | mapping of key-value pairs | `{'name':'DSCI','code':511,'credits':2}` |\n", - "| none | `NoneType` | represents no value | `None` |" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Numeric Types" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "x = 42" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "int" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "42\n" - ] - } - ], - "source": [ - "print(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "42" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x # in Jupyter/IPython we don't need to explicitly print for the last line of a cell" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "pi = 3.14159" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3.14159\n" - ] - } - ], - "source": [ - "print(pi)" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "float" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(pi)" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "λ = 2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Arithmetic Operators\n", - "\n", - "The syntax for the arithmetic operators are:\n", - "\n", - "| Operator | Description |\n", - "| :---: | :---: |\n", - "| `+` | addition |\n", - "| `-` | subtraction |\n", - "| `*` | multiplication |\n", - "| `/` | division |\n", - "| `**` | exponentiation |\n", - "| `//` | integer division |\n", - "| `%` | modulo |\n", - "\n", - "Let's apply these operators to numeric types and observe the results." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "15" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "1 + 2 + 3 + 4 + 5" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.30000000000000004" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "0.1 + 0.2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "```{tip}\n", - "From Firas: This is floating point arithmetic. For an explanation of what's going on, [see this tutorial](https://docs.python.org/3/tutorial/floatingpoint.html).\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "6.28318" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2 * 3.14159" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1024" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2**10" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "int" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(2**10)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1024.0" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2.0**10" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [], - "source": [ - "int_2 = 2" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [], - "source": [ - "float_2 = 2.0" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [], - "source": [ - "float_2_again = 2." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "50.5" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "101 / 2" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "50" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "101 // 2 # \"integer division\" - always rounds down" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "101 % 2 # \"101 mod 2\", or the remainder when 101 is divided by 2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### None\n", - "\n", - "- `NoneType` is its own type in Python.\n", - "- It only has one possible value, `None`" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [], - "source": [ - "x = None" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "None\n" - ] - } - ], - "source": [ - "print(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "NoneType" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(x)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You may have seen similar things in other languages, like `null` in Java, etc." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Strings\n", - "\n", - "- Text is stored as a type called a string. \n", - "- We think of a string as a sequence of characters. \n", - "- We write strings as characters enclosed with either:\n", - " - single quotes, e.g., `'Hello'` \n", - " - double quotes, e.g., `\"Goodbye\"`\n", - " - triple single quotes, e.g., `'''Yesterday'''`\n", - " - triple double quotes, e.g., `\"\"\"Tomorrow\"\"\"`" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [], - "source": [ - "my_name = \"Mike Gelbart\"" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Mike Gelbart\n" - ] - } - ], - "source": [ - "print(my_name)" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 29, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(my_name)" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [], - "source": [ - "course = 'DSCI 511'" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "DSCI 511\n" - ] - } - ], - "source": [ - "print(course)" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(course)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If the string contains a quotation or apostrophe, we can use double quotes or triple quotes to define the string." - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [], - "source": [ - "sentence = \"It's a rainy day.\"" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "It's a rainy day.\n" - ] - } - ], - "source": [ - "print(sentence)" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(sentence)" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": {}, - "outputs": [], - "source": [ - "saying = '''They say: \n", - "\"It's a rainy day!\"'''" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "They say: \n", - "\"It's a rainy day!\"\n" - ] - } - ], - "source": [ - "print(saying)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Boolean\n", - "\n", - "- The Boolean (`bool`) type has two values: `True` and `False`. " - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "outputs": [], - "source": [ - "the_truth = True" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], - "source": [ - "print(the_truth)" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "bool" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(the_truth)" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [], - "source": [ - "lies = False" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n" - ] - } - ], - "source": [ - "print(lies)" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "bool" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(lies)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Comparison Operators\n", - "\n", - "Compare objects using comparison operators. The result is a Boolean value.\n", - "\n", - "| Operator | Description |\n", - "| :---: | :--- |\n", - "| `x == y ` | is `x` equal to `y`? |\n", - "| `x != y` | is `x` not equal to `y`? |\n", - "| `x > y` | is `x` greater than `y`? |\n", - "| `x >= y` | is `x` greater than or equal to `y`? |\n", - "| `x < y` | is `x` less than `y`? |\n", - "| `x <= y` | is `x` less than or equal to `y`? |\n", - "| `x is y` | is `x` the same object as `y`? |" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 46, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2 < 3" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "\"Data Science\" != \"Deep Learning\"" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 48, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2 == \"2\"" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 49, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2 == 2.0" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note: we will discuss `is` next week." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Operators on Boolean values.\n", - "\n", - "| Operator | Description |\n", - "| :---: | :--- |\n", - "|`x and y`| are `x` and `y` both true? |\n", - "|`x or y` | is at least one of `x` and `y` true? |\n", - "| `not x` | is `x` false? | " - ] - }, - { - "cell_type": "code", - "execution_count": 51, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 51, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "True and True" - ] - }, - { - "cell_type": "code", - "execution_count": 50, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 50, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "True and False" - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 52, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "False or False" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 53, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(\"Python 2\" != \"Python 3\") and (2 <= 3)" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 54, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "not True" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 55, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "not not True" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Casting\n", - "\n", - "- Sometimes (but rarely) we need to explicitly **cast** a value from one type to another.\n", - "- Python tries to do something reasonable, or throws an error if it has no ideas." - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 56, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = int(5.0)\n", - "x" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "int" - ] - }, - "execution_count": 57, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'5.0'" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x = str(5.0)\n", - "x" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "str(5.0) == 5.0" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "execution": { - "iopub.execute_input": "2021-01-10T01:58:33.810Z", - "iopub.status.busy": "2021-01-10T01:58:33.749Z", - "iopub.status.idle": "2021-01-10T01:58:33.909Z", - "shell.execute_reply": "2021-01-10T01:58:33.594Z" - } - }, - "outputs": [], - "source": [ - "# list(5.0) # there is no reasonable thing to do here" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 62, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "int(5.3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Lists and Tuples (20 min)\n", - "\n", - "- Lists and tuples allow us to store multiple things (\"elements\") in a single object.\n", - "- The elements are _ordered_." - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [], - "source": [ - "my_list = [1, 2, \"THREE\", 4, 0.5]" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 2, 'THREE', 4, 0.5]\n" - ] - } - ], - "source": [ - "print(my_list)" - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "list" - ] - }, - "execution_count": 66, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(my_list)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can get the length of the list with `len`:" - ] - }, - { - "cell_type": "code", - "execution_count": 67, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 67, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(my_list)" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": {}, - "outputs": [], - "source": [ - "today = (1, 2, \"THREE\", 4, 0.5)" - ] - }, - { - "cell_type": "code", - "execution_count": 69, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(1, 2, 'THREE', 4, 0.5)\n" - ] - } - ], - "source": [ - "print(today)" - ] - }, - { - "cell_type": "code", - "execution_count": 70, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tuple" - ] - }, - "execution_count": 70, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(today)" - ] - }, - { - "cell_type": "code", - "execution_count": 71, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 71, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(today)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Indexing and Slicing Sequences\n", - "\n", - "- We can access values inside a list, tuple, or string using the backet syntax. \n", - "- Python uses zero-based indexing, which means the first element of the list is in position 0, not position 1. \n", - "- Sadly, R uses one-based indexing, so get ready to be confused." - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 'THREE', 4, 0.5]" - ] - }, - "execution_count": 72, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list" - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1" - ] - }, - "execution_count": 73, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.5" - ] - }, - "execution_count": 74, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[4]" - ] - }, - { - "cell_type": "code", - "execution_count": 75, - "metadata": { - "tags": [ - "skip-execution" - ] - }, - "outputs": [ - { - "ename": "IndexError", - "evalue": "list index out of range", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmy_list\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m: list index out of range" - ] - } - ], - "source": [ - "my_list[5]" - ] - }, - { - "cell_type": "code", - "execution_count": 77, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.5" - ] - }, - "execution_count": 77, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "today[4]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We use negative indices to count backwards from the end of the list." - ] - }, - { - "cell_type": "code", - "execution_count": 80, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 'THREE', 4, 0.5]" - ] - }, - "execution_count": 80, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list" - ] - }, - { - "cell_type": "code", - "execution_count": 81, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.5" - ] - }, - "execution_count": 81, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[-1]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We use the colon `:` to access a subsequence. This is called \"slicing\"." - ] - }, - { - "cell_type": "code", - "execution_count": 84, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[2, 'THREE', 4]" - ] - }, - "execution_count": 84, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[1:4]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Above: note that the start is inclusive and the end is exclusive.\n", - "- So `my_list[1:3]` fetches elements 1 and 2, but not 3.\n", - "- In other words, it gets the 2nd and 3rd elements in the list." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can omit the start or end:" - ] - }, - { - "cell_type": "code", - "execution_count": 85, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 'THREE']" - ] - }, - "execution_count": 85, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[:3]" - ] - }, - { - "cell_type": "code", - "execution_count": 86, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[4, 0.5]" - ] - }, - "execution_count": 86, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[3:]" - ] - }, - { - "cell_type": "code", - "execution_count": 87, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 'THREE', 4, 0.5]" - ] - }, - "execution_count": 87, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[:] # *almost* same as my_list - more details next week" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Strings behave the same as lists and tuples when it comes to indexing and slicing." - ] - }, - { - "cell_type": "code", - "execution_count": 88, - "metadata": {}, - "outputs": [], - "source": [ - "alphabet = \"abcdefghijklmnopqrstuvwxyz\"" - ] - }, - { - "cell_type": "code", - "execution_count": 89, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'a'" - ] - }, - "execution_count": 89, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 90, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'z'" - ] - }, - "execution_count": 90, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[-1]" - ] - }, - { - "cell_type": "code", - "execution_count": 91, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'x'" - ] - }, - "execution_count": 91, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[-3]" - ] - }, - { - "cell_type": "code", - "execution_count": 92, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'abcde'" - ] - }, - "execution_count": 92, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[:5]" - ] - }, - { - "cell_type": "code", - "execution_count": 93, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'mnopqrst'" - ] - }, - "execution_count": 93, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[12:20]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### List Methods\n", - "\n", - "- A list is an object and it has methods for interacting with its data. \n", - "- For example, `list.append(item)` appends an item to the end of the list. \n", - "- See the documentation for more [list methods](https://docs.python.org/3/tutorial/datastructures.html#more-on-lists)." - ] - }, - { - "cell_type": "code", - "execution_count": 94, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[2, 3, 5, 7, 11]" - ] - }, - "execution_count": 94, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "primes = [2,3,5,7,11]\n", - "primes" - ] - }, - { - "cell_type": "code", - "execution_count": 95, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 95, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 114, - "metadata": {}, - "outputs": [], - "source": [ - "primes.append(13)" - ] - }, - { - "cell_type": "code", - "execution_count": 115, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[2,\n", - " 3,\n", - " 5,\n", - " 7,\n", - " 11,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13,\n", - " 13]" - ] - }, - "execution_count": 115, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "primes" - ] - }, - { - "cell_type": "code", - "execution_count": 116, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "22" - ] - }, - "execution_count": 116, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 117, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "13" - ] - }, - "execution_count": 117, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "max(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 118, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 118, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "min(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 119, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "249" - ] - }, - "execution_count": 119, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sum(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 120, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 3, 'Hello', 7]" - ] - }, - "execution_count": 120, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "[1,2,3] + [\"Hello\", 7]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Sets\n", - "\n", - "- Another built-in Python data type is the `set`, which stores an _un-ordered_ list of _unique_ items.\n", - "- More on sets in DSCI 512." - ] - }, - { - "cell_type": "code", - "execution_count": 121, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{2, 3, 5, 11}" - ] - }, - "execution_count": 121, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s = {2,3,5,11}\n", - "s" - ] - }, - { - "cell_type": "code", - "execution_count": 122, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 122, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "{1,2,3} == {3,2,1}" - ] - }, - { - "cell_type": "code", - "execution_count": 123, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 123, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "[1,2,3] == [3,2,1]" - ] - }, - { - "cell_type": "code", - "execution_count": 124, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{2, 3, 5, 11}" - ] - }, - "execution_count": 124, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s.add(2) # does nothing\n", - "s" - ] - }, - { - "cell_type": "code", - "execution_count": 125, - "metadata": { - "tags": [ - "skip-execution" - ] - }, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'set' object is not subscriptable", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ms\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: 'set' object is not subscriptable" - ] - } - ], - "source": [ - "s[0]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Above: throws an error because elements are not ordered." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Mutable vs. Immutable Types\n", - "\n", - "- Strings and tuples are immutable types which means they cannot be modified. \n", - "- Lists are mutable and we can assign new values for its various entries. \n", - "- This is the main difference between lists and tuples." - ] - }, - { - "cell_type": "code", - "execution_count": 126, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['Indiana', 'Fang', 'Linsey']" - ] - }, - "execution_count": 126, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "names_list = [\"Indiana\",\"Fang\",\"Linsey\"]\n", - "names_list" - ] - }, - { - "cell_type": "code", - "execution_count": 128, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['Cool guy', 'Fang', 'Linsey']" - ] - }, - "execution_count": 128, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "names_list[0] = \"Cool guy\"\n", - "names_list" - ] - }, - { - "cell_type": "code", - "execution_count": 129, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "('Indiana', 'Fang', 'Linsey')" - ] - }, - "execution_count": 129, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "names_tuple = (\"Indiana\",\"Fang\",\"Linsey\")\n", - "names_tuple" - ] - }, - { - "cell_type": "code", - "execution_count": 130, - "metadata": { - "tags": [ - "skip-execution" - ] - }, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'tuple' object does not support item assignment", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnames_tuple\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"Not cool guy\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" - ] - } - ], - "source": [ - "names_tuple[0] = \"Not cool guy\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Same goes for strings. Once defined we cannot modifiy the characters of the string." - ] - }, - { - "cell_type": "code", - "execution_count": 131, - "metadata": {}, - "outputs": [], - "source": [ - "my_name = \"Mike\"" - ] - }, - { - "cell_type": "code", - "execution_count": 132, - "metadata": { - "tags": [ - "skip-execution" - ] - }, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'str' object does not support item assignment", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmy_name\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'q'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment" - ] - } - ], - "source": [ - "my_name[-1] = 'q'" - ] - }, - { - "cell_type": "code", - "execution_count": 137, - "metadata": {}, - "outputs": [], - "source": [ - "x = ([1,2,3],5)" - ] - }, - { - "cell_type": "code", - "execution_count": 138, - "metadata": { - "tags": [ - "skip-execution" - ] - }, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'tuple' object does not support item assignment", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m7\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" - ] - } - ], - "source": [ - "x[1] = 7" - ] - }, - { - "cell_type": "code", - "execution_count": 139, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "([1, 2, 3], 5)" - ] - }, - "execution_count": 139, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x" - ] - }, - { - "cell_type": "code", - "execution_count": 140, - "metadata": {}, - "outputs": [], - "source": [ - "x[0][1] = 4" - ] - }, - { - "cell_type": "code", - "execution_count": 141, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "([1, 4, 3], 5)" - ] - }, - "execution_count": 141, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Break (5 min)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## String Methods (5 min)\n", - "\n", - "- There are various useful string methods in Python.\n", - "- MDS-CL students will soon be the experts we can go to for help!" - ] - }, - { - "cell_type": "code", - "execution_count": 142, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "HOW ARE YOU TODAY?\n" - ] - } - ], - "source": [ - "all_caps = \"HOW ARE YOU TODAY?\"\n", - "print(all_caps)" - ] - }, - { - "cell_type": "code", - "execution_count": 145, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'how are you today?'" - ] - }, - "execution_count": 145, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "new_str = all_caps.lower()\n", - "new_str" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note that the method lower doesn't change the original string but rather returns a new one.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 146, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'HOW ARE YOU TODAY?'" - ] - }, - "execution_count": 146, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "all_caps" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There are *many* string methods. Check out the [documentation](https://docs.python.org/3/library/stdtypes.html#string-methods)." - ] - }, - { - "cell_type": "code", - "execution_count": 147, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['HOW', 'ARE', 'YOU', 'TODAY?']" - ] - }, - "execution_count": 147, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "all_caps.split()" - ] - }, - { - "cell_type": "code", - "execution_count": 148, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 148, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "all_caps.count(\"O\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "One can explicitly cast a string to a list:" - ] - }, - { - "cell_type": "code", - "execution_count": 151, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['H',\n", - " 'O',\n", - " 'W',\n", - " ' ',\n", - " 'A',\n", - " 'R',\n", - " 'E',\n", - " ' ',\n", - " 'Y',\n", - " 'O',\n", - " 'U',\n", - " ' ',\n", - " 'T',\n", - " 'O',\n", - " 'D',\n", - " 'A',\n", - " 'Y',\n", - " '?']" - ] - }, - "execution_count": 151, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "caps_list = list(all_caps)\n", - "caps_list" - ] - }, - { - "cell_type": "code", - "execution_count": 152, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "18" - ] - }, - "execution_count": 152, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(all_caps)" - ] - }, - { - "cell_type": "code", - "execution_count": 153, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "18" - ] - }, - "execution_count": 153, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(caps_list)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### String formatting\n", - "\n", - "- Python has ways of creating strings by \"filling in the blanks\" and formatting them nicely. \n", - "- There are a few ways of doing this. See [here](https://realpython.com/python-string-formatting/) and [here](https://stackoverflow.com/questions/5082452/string-formatting-vs-format) for some discussion." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Old formatting style (borrowed from the C programming language):" - ] - }, - { - "cell_type": "code", - "execution_count": 154, - "metadata": {}, - "outputs": [], - "source": [ - "template = \"Hello, my name is %s. I am %.2f years old.\"" - ] - }, - { - "cell_type": "code", - "execution_count": 155, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Hello, my name is Newborn Baby. I am 0.33 years old.'" - ] - }, - "execution_count": 155, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "template % (\"Newborn Baby\", 4/12)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "New formatting style (see [documentation](https://docs.python.org/3/library/stdtypes.html#str.format)):" - ] - }, - { - "cell_type": "code", - "execution_count": 156, - "metadata": {}, - "outputs": [], - "source": [ - "template_new = \"Hello, my name is {}. I am {:.2f} years old.\"" - ] - }, - { - "cell_type": "code", - "execution_count": 157, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Hello, my name is Newborn Baby. I am 0.33 years old.'" - ] - }, - "execution_count": 157, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "template_new.format('Newborn Baby', 4/12)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Newer formatting style (see [here](https://realpython.com/python-f-strings/#f-strings-a-new-and-improved-way-to-format-strings-in-python)) - note the `f` before the start of the string:" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Hello, my name is Newborn Baby. I am 0.33 years old.'" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "name = \"Newborn Baby\"\n", - "age = 4/12\n", - "template_new = f'Hello, my name is {name}. I am {age:.2f} years old.'\n", - "template_new" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Dictionaries (10 min)\n", - "\n", - "A dictionary is a mapping between key-values pairs." - ] - }, - { - "cell_type": "code", - "execution_count": 158, - "metadata": {}, - "outputs": [], - "source": [ - "house = {'bedrooms': 3, 'bathrooms': 2, 'city': 'Vancouver', 'price': 2499999, 'date_sold': (1,3,2015)}\n", - "\n", - "condo = {'bedrooms' : 2, \n", - " 'bathrooms': 1, \n", - " 'city' : 'Burnaby', \n", - " 'price' : 699999, \n", - " 'date_sold': (27,8,2011)\n", - " }" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can access a specific field of a dictionary with square brackets:" - ] - }, - { - "cell_type": "code", - "execution_count": 159, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2499999" - ] - }, - "execution_count": 159, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "house['price']" - ] - }, - { - "cell_type": "code", - "execution_count": 160, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Burnaby'" - ] - }, - "execution_count": 160, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo['city']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also edit dictionaries (they are mutable):" - ] - }, - { - "cell_type": "code", - "execution_count": 162, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'city': 'Burnaby',\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011)}" - ] - }, - "execution_count": 162, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo['price'] = 5 # price already in the dict\n", - "condo" - ] - }, - { - "cell_type": "code", - "execution_count": 163, - "metadata": {}, - "outputs": [], - "source": [ - "condo['flooring'] = \"wood\"" - ] - }, - { - "cell_type": "code", - "execution_count": 164, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'city': 'Burnaby',\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011),\n", - " 'flooring': 'wood'}" - ] - }, - "execution_count": 164, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can delete fields entirely (though I rarely use this):" - ] - }, - { - "cell_type": "code", - "execution_count": 165, - "metadata": {}, - "outputs": [], - "source": [ - "del condo[\"city\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 166, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011),\n", - " 'flooring': 'wood'}" - ] - }, - "execution_count": 166, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo" - ] - }, - { - "cell_type": "code", - "execution_count": 167, - "metadata": {}, - "outputs": [], - "source": [ - "condo[5] = 443345" - ] - }, - { - "cell_type": "code", - "execution_count": 168, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011),\n", - " 'flooring': 'wood',\n", - " 5: 443345}" - ] - }, - "execution_count": 168, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo" - ] - }, - { - "cell_type": "code", - "execution_count": 169, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011),\n", - " 'flooring': 'wood',\n", - " 5: 443345,\n", - " (1, 2, 3): 777}" - ] - }, - "execution_count": 169, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo[(1,2,3)] = 777\n", - "condo" - ] - }, - { - "cell_type": "code", - "execution_count": 170, - "metadata": {}, - "outputs": [ - { - "ename": "KeyError", - "evalue": "'nothere'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcondo\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"nothere\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m: 'nothere'" - ] - } - ], - "source": [ - "condo[\"nothere\"]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A sometimes useful trick about default values:" - ] - }, - { - "cell_type": "code", - "execution_count": 171, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 171, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo[\"bedrooms\"]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "is shorthand for" - ] - }, - { - "cell_type": "code", - "execution_count": 172, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 172, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo.get(\"bedrooms\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "With this syntax you can also use default values:" - ] - }, - { - "cell_type": "code", - "execution_count": 173, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 173, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo.get(\"bedrooms\", \"unknown\")" - ] - }, - { - "cell_type": "code", - "execution_count": 174, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'unknown'" - ] - }, - "execution_count": 174, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo.get(\"fireplaces\", \"unknown\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- A common operation is finding the maximum dictionary key by value.\n", - "- There are a few ways to do this, see [this StackOverflow page](https://stackoverflow.com/questions/268272/getting-key-with-maximum-value-in-dictionary).\n", - "- One way of doing it:" - ] - }, - { - "cell_type": "code", - "execution_count": 175, - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'word_lengths' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mword_lengths\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mword_lengths\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mNameError\u001b[0m: name 'word_lengths' is not defined" - ] - } - ], - "source": [ - "max(word_lengths, key=word_lengths.get)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We saw `word_lengths.get` above - it is saying that we should call this function on each key of the dict to decide how to sort." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Empties" - ] - }, - { - "cell_type": "code", - "execution_count": 176, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 176, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "lst = list() # empty list\n", - "lst" - ] - }, - { - "cell_type": "code", - "execution_count": 177, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 177, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "lst = [] # empty list\n", - "lst" - ] - }, - { - "cell_type": "code", - "execution_count": 178, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "()" - ] - }, - "execution_count": 178, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tup = tuple() # empty tuple\n", - "tup" - ] - }, - { - "cell_type": "code", - "execution_count": 179, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "()" - ] - }, - "execution_count": 179, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tup = () # empty tuple\n", - "tup" - ] - }, - { - "cell_type": "code", - "execution_count": 180, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{}" - ] - }, - "execution_count": 180, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dic = dict() # empty dict\n", - "dic" - ] - }, - { - "cell_type": "code", - "execution_count": 181, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{}" - ] - }, - "execution_count": 181, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dic = {} # empty dict\n", - "dic" - ] - }, - { - "cell_type": "code", - "execution_count": 182, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "set()" - ] - }, - "execution_count": 182, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "st = set() # emtpy set\n", - "st" - ] - }, - { - "cell_type": "code", - "execution_count": 183, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "dict" - ] - }, - "execution_count": 183, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "st = {} # NOT an empty set!\n", - "type(st)" - ] - }, - { - "cell_type": "code", - "execution_count": 184, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "set" - ] - }, - "execution_count": 184, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "st = {1}\n", - "type(st)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Conditionals (10 min)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- [Conditional statements](https://docs.python.org/3/tutorial/controlflow.html) allow us to write programs where only certain blocks of code are executed depending on the state of the program. \n", - "- Let's look at some examples and take note of the keywords, syntax and indentation. \n", - "- Check out the [Python documentation](https://docs.python.org/3/tutorial/controlflow.html) and [Think Python (Chapter 5)](http://greenteapress.com/thinkpython/html/thinkpython006.html) for more information about conditional execution." - ] - }, - { - "cell_type": "code", - "execution_count": 189, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "What's your name?mike\n", - "That's my name too!\n" - ] - } - ], - "source": [ - "name = input(\"What's your name?\")\n", - "\n", - "if name.lower() == 'mike':\n", - " print(\"That's my name too!\")\n", - "elif name.lower() == 'santa':\n", - " print(\"That's a funny name.\")\n", - "else:\n", - " print(\"Hello {}! That's a cool name.\".format(name))\n", - "\n", - " print('Nice to meet you!')" - ] - }, - { - "cell_type": "code", - "execution_count": 190, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 190, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "bool(None)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The main points to notice:\n", - "\n", - "* Use keywords `if`, `elif` and `else`\n", - "* The colon `:` ends each conditional expression\n", - "* Indentation (by 4 empty space) defines code blocks\n", - "* In an `if` statement, the first block whose conditional statement returns `True` is executed and the program exits the `if` block\n", - "* `if` statements don't necessarily need `elif` or `else`\n", - "* `elif` lets us check several conditions\n", - "* `else` lets us evaluate a default block if all other conditions are `False`\n", - "* the end of the entire `if` statement is where the indentation returns to the same level as the first `if` keyword" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If statements can also be **nested** inside of one another:" - ] - }, - { - "cell_type": "code", - "execution_count": 192, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "What's your name?supersam\n", - "Hello supersam! That's a cool name.\n", - "Do you have superpowers?\n", - "Nice to meet you!\n" - ] - } - ], - "source": [ - "name = input(\"What's your name?\")\n", - "\n", - "if name.lower() == 'mike':\n", - " print(\"That's my name too!\")\n", - "elif name.lower() == 'santa':\n", - " print(\"That's a funny name.\")\n", - "else:\n", - " print(\"Hello {0}! That's a cool name.\".format(name))\n", - " if name.lower().startswith(\"super\"):\n", - " print(\"Do you have superpowers?\")\n", - "\n", - "print('Nice to meet you!')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Inline if/else" - ] - }, - { - "cell_type": "code", - "execution_count": 193, - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'short list'" - ] - }, - "execution_count": 193, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "words = [\"the\", \"list\", \"of\", \"words\"]\n", - "\n", - "x = \"long list\" if len(words) > 10 else \"short list\"\n", - "x" - ] - }, - { - "cell_type": "code", - "execution_count": 194, - "metadata": {}, - "outputs": [], - "source": [ - "if len(words) > 10:\n", - " x = \"long list\"\n", - "else:\n", - " x = \"short list\"" - ] - }, - { - "cell_type": "code", - "execution_count": 195, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'short list'" - ] - }, - "execution_count": 195, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### (optional) short-circruiting" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "BLAH # not defined" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "True or BLAH" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "True and BLAH" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "False and BLAH" - ] - } - ], - "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.8.3" - }, - "nteract": { - "version": "0.27.0" - }, - "toc-showmarkdowntxt": false, - "toc-showtags": false - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notes/demo01/lecture2.ipynb b/notes/demo01/lecture2.ipynb deleted file mode 100644 index 2f0b6ac..0000000 --- a/notes/demo01/lecture2.ipynb +++ /dev/null @@ -1,814 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "# Platforms for Data Science" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "slideshow": { - "slide_type": "skip" - }, - "tags": [ - "remove-input" - ] - }, - "outputs": [], - "source": [ - "from IPython.display import IFrame\n", - "from IPython.display import Markdown\n", - "# Additional styling ; should be moved into helpers\n", - "from IPython.core.display import display, HTML\n", - "HTML(''.format(open('styler.css').read()))\n", - "Q1 = IFrame('https://app.sli.do/event/0oandysw/embed/polls/bcf12c99-53c2-467c-9635-b6564db67e11', width=450, height=550)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Lecture Outline" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- Introduction (40 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- Break (10 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- Course Tools survey (2 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- Syllabus walk-through (10 minutes)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- Demo of DATA 530 Lab and GitHub (20 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Introduction" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### The Essence of the course\n", - "\n", - "The overall goal of this course is for you to:\n", - "\n", - "**Install, configure, and use a variety of data analysis tools and software packages**\n", - "\n", - "This course covers how to configure data analysis environments, select appropriate tools for particular tasks, read documentation and get help, and use a variety of software packages for data analysis.\n", - "\n", - " - Other courses will build on this course by going deeper into the application of these systems and techniques.\n", - " \n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Course Objectives\n", - "\n", - "1. Install and setup a variety of software tools and programs used by data analysts" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "2. Perform basic and advanced data analysis and visualization in Excel" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "3. Able to setup IDEs and write small programs in Python and R" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "4. Understand the pros and cons of each tool/software package and criteria to select the best tool for the job" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Course Goals (for me)\n", - "\n", - "1) Provide the information in a simple, concise, and effective way for learning." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "2) Strive for all students to understand the material and excel at the course." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "3) Be available for questions during class time, office hours, and at other times as needed." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "4) Provide an introduction to a variety of data analysis software and systems." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "5) Emphasize the use of Excel as a easy-to-use, general tool for data analysis." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Academic Integrity\n", - "\n", - "\n", - "Cheating is strictly prohibited and is taken very seriously by UBC. A guideline to what constitutes cheating:\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- **Labs**\n", - " - Submitting code produced by others.\n", - " - Working in groups to solve questions and/or comparing answers to questions once they have been solved (except for group assignments).\n", - " - Discussing HOW to solve a particular question instead of WHAT the question involves." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- **Exams (Quizzes)**\n", - " - DATA 530 and 531 Quizzes are open book\n", - " - No communication about course content is permitted (with classmates, or others)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### How to Excel in this course" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- **Attend class**\n", - " - If required, Read notes **before** class as preparation and try the questions on your own\n", - " - Participate in class activities and questions (clickers)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- **Attend and complete all labs**\n", - " - Labs practice the fundamental employable skills as well as being for marks." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- **Practice on your own. Practice makes perfect.**\n", - " - Do more questions than in the labs.\n", - " - Read the additional reference material and perform practice questions." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Systems and tools" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "1. Course Material: \n", - " - Canvas, this site, and Github (all are identical)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "2. Marks:\n", - " - Canvas" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "3. Feedback\n", - " - Canvas and (sometimes) Github " - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "4. Hardware\n", - " - Your laptop (mostly)\n", - " - Cloud computing (when needed): https://ubc.syzygy.ca" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Lab Assignments\n", - "\n", - "- Weekly lab assignments are worth 40% of your overall grade.\n", - "\n", - "- Lab assignments will likely take more than the 1.5 hours of lab time.\n", - "\n", - "- You have until after the following lab to complete each lab.\n", - " - Late labs will not be accepted (except for grace period)\n", - " \n", - "- Lab assignments are done individually but can be worked on collaboratively.\n", - "\n", - "- The lab assignments are critical to learning the material and are designed both to prepare you for the exams and build up your skills!" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Labs during COVID-19\n", - "\n", - "- Lab sections are 3 hours long, split into two to ensure physical distancing \n", - " - Section 1: 12:30 - 14:00\n", - " - Section 2: 14:00 - 15:30\n", - " \n", - "- If there are 16 people that would like to attend the physical lab, we should split evenly so half are in each section\n", - "\n", - "- Need to coordinate and figure out who would like to attend labs\n", - " - I don't have a good system at the moment, maybe we can brainstorm together?" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Breakout rooms activity [10 mins]\n", - "\n", - "We will split into breakout rooms for this activity, in groups of about 4\n", - "\n", - "#### Your Task: In your small groups, brainstorm ways to organize \"who goes where, when\".\n", - "\n", - "- Keep in mind that many of us will be attending remotely, and there are timezones to consider!\n", - "- Write your ideas on Slack in the DATA 530 channel - use threads to comment on others' ideas!\n", - "- Consider, \"The Zen of Python\":" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The Zen of Python, by Tim Peters\n", - "\n", - "Beautiful is better than ugly.\n", - "Explicit is better than implicit.\n", - "Simple is better than complex.\n", - "Complex is better than complicated.\n", - "Flat is better than nested.\n", - "Sparse is better than dense.\n", - "Readability counts.\n", - "Special cases aren't special enough to break the rules.\n", - "Although practicality beats purity.\n", - "Errors should never pass silently.\n", - "Unless explicitly silenced.\n", - "In the face of ambiguity, refuse the temptation to guess.\n", - "There should be one-- and preferably only one --obvious way to do it.\n", - "Although that way may not be obvious at first unless you're Dutch.\n", - "Now is better than never.\n", - "Although never is often better than *right* now.\n", - "If the implementation is hard to explain, it's a bad idea.\n", - "If the implementation is easy to explain, it may be a good idea.\n", - "Namespaces are one honking great idea -- let's do more of those!\n" - ] - } - ], - "source": [ - "import this " - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### In-class \"Clicker questions\" AKA Participation\n", - "\n", - "To promote understanding, 10% of your overall grade is allocated to answering in-class questions (called Clickers).\n", - "\n", - "- These questions are answered using [Sli.do](https://sli.do) and you will need to create an account.\n", - "\n", - "- You should download the apps and bookmark the site for convenience\n", - "\n", - "- At different times during all the lectures, questions reviewing material will be asked. Reponses are given using Sli.do polls.\n", - "\n", - "- We will do several of these today to get you familiar with the system" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Activity: A typical Clicker Sequence\n", - "\n", - "- Part 1: Instructor asks a question and students answer" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "- Part 2: Instructor shows the results (Optional) and opens breakout rooms for students to discuss their choices with others" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - " - Part 3: Instructor asks the same question again and we see if there is convergence" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "### Clicker Question Activity [5 mins]" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "Q1" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "#### Results and breakout rooms\n", - "\n", - "(Part 2: Instructor shows the results (Optional) and opens breakout rooms for students to discuss their choices with others" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "#### Re-vote and Debrief\n", - "\n", - "(Part 3: Instructor asks the same question again and we see if there is convergence)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Break (10 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Course Tools Survey (2 mins)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "IFrame('https://ubc.ca1.qualtrics.com/jfe/form/SV_eboA3fyVCFkhixn',width=750,height=1300)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Syllabus walk-through (10 minutes)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "### Content covered\n", - "\n", - "- How learning works\n", - "- Piazza for Q&A, Slack for conversations\n", - "- Canvas structure\n", - "- Course structure\n", - "- Course policies\n", - "- Due dates and grace period (for DATA 530 and 531 only)\n", - "- Quiz policies\n", - "- Labs" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Demo of DATA 530 Lab and GitHub (20 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "### Content covered\n", - "\n", - "- Navigating GitHub\n", - "- Uploading files on GitHub\n", - " - Uploading to a specific folder\n", - "- Accepting a lab assignment\n", - "- Cloning a repository (repo)\n", - " - `git clone `\n", - "- Making changes to a local version of a repo\n", - " - `code README.md` and then make changes\n", - "- Commit your changes to the repository\n", - " - `git add -A`\n", - " - `git commit -m \"This is a test commit\"`\n", - "- Pushing the changes above\n", - " - `git push`" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "slideshow": { - "slide_type": "skip" - }, - "tags": [ - "remove-input" - ] - }, - "outputs": [], - "source": [ - "## RISE Template\n", - "\n", - "from traitlets.config.manager import BaseJSONConfigManager\n", - "from pathlib import Path\n", - "path = Path.home() / \".jupyter\" / \"nbconfig\"\n", - "cm = BaseJSONConfigManager(config_dir=str(path))\n", - "tmp = cm.update(\n", - " \"rise\",\n", - " {\n", - " \"theme\": \"sky\", # https://revealjs.com/themes/\n", - " \"transition\": \"fade\",\n", - " \"start_slideshow_at\": \"selected\",\n", - " \"autolaunch\": False,\n", - " \"width\": \"100%\",\n", - " \"height\": \"100%\",\n", - " \"header\": \"\",\n", - " \"footer\":\"\",\n", - " \"scroll\": True,\n", - " \"enable_chalkboard\": True,\n", - " \"slideNumber\": True,\n", - " \"center\": False,\n", - " \"controlsLayout\": \"edges\",\n", - " \"slideNumber\": True,\n", - " \"hash\": True,\n", - " }\n", - " )" - ] - } - ], - "metadata": { - "celltoolbar": "Tags", - "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.8.3" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notes/demo01/lecture3.md b/notes/demo01/lecture3.md deleted file mode 100644 index 643f4d1..0000000 --- a/notes/demo01/lecture3.md +++ /dev/null @@ -1,13 +0,0 @@ -# Introduction to Microsoft Excel - - - -## Excel file using in lecture. - -You can download the [Excel file used in lecture here](https://github.com/firasm/bits/raw/master/sales.xlsx) - -## Sli.do Polls - -You can go to [https://sli.do/data530](https://sli.do/data301) in a new tab or use the embedded poll here: - - \ No newline at end of file diff --git a/notes/demo01/styler.css b/notes/demo01/styler.css deleted file mode 100644 index cc13360..0000000 --- a/notes/demo01/styler.css +++ /dev/null @@ -1,63 +0,0 @@ -/*.container { width:100% !important; }*/ - -div.prompt {display:none} - -div.output_subarea {max-width:100%} - -/* These below are from the altair_talk css */ - -/* ---------- markdown cells - */ -body.rise-enabled div.inner_cell>div.text_cell_render.rendered_html { - font-size: 100%; -} - - -/* ---------- code blocks inside markdown - i.e. within ``` lines, or 4-space indented - */ -div.inner_cell>div.text_cell_render.rendered_html>pre { - margin: 0px; -} - -/* ----------- code to remove space above markdown headers - */ -div.inner_cell>div.text_cell_render.rendered_html h1 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h2 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h3 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h4 { - margin-top: 0px; -} - -div.inner_cell>div.text_cell_render.rendered_html>pre>code { - font-size: 70%; -} - -/* ---------- tables (from SO) - */ -.rendered_html table, .rendered_html th, .rendered_html tr, .rendered_html td { - font-size: 120%; -} - -/* ---------- Left part of code cells - from this SO answer: https://stackoverflow.com/a/47263575; - /* Narrow the prompts */ -div.prompt_container { - min-width: 5ex; -} -/* Hide prompts altogether for non-conda cells */ -.cell:not(.code_cell) .prompt { - display: none; -} -/* ---------- Width of cells - */ -.container { - width:95% !important; -} - diff --git a/notes/demo02/demo02_summary.md b/notes/demo02/demo02_summary.md deleted file mode 100755 index 6a1a964..0000000 --- a/notes/demo02/demo02_summary.md +++ /dev/null @@ -1,44 +0,0 @@ -(page_topic2_demo)= -Week 2 Summary -======================= - -## How this course is organized - -Hello students! Welcome to Week 2 - this week we will begin the physics part of our class! - -
- -
- -## How to watch flipped lecture videos - -
- -
- -Optional: [Showing the differences between a Traditional and a Flipped Classroom](https://www.youtube.com/watch?v=yzMFdDT6FSA). - - -## List of things to do this week - -Below is a list of things you need to do this week, links to where you can do them, as well as roughly the order you should do it. -Note that these are just SUGGESTIONS and you are by no means required to them this way. -I have put the labs at the end, but if your lab section is earlier in the week, you may want to shift things around. - - - - - - - - -```{tip} -Normally the homework for this week would be due by Thursday at 18:00, but this week because there are/were textbook issues, I have extended this to next Thursday () -``` - - - - - - - \ No newline at end of file diff --git a/notes/demo02/homework.md b/notes/demo02/homework.md deleted file mode 100644 index 3f48661..0000000 --- a/notes/demo02/homework.md +++ /dev/null @@ -1,11 +0,0 @@ -# Homework - -````{card} - -This week the homework assignment is on Chapter 3, and is posted on Mastering physics. - -```{button-link} https://portal.mypearson.com -Mastering Physics - -``` -```` \ No newline at end of file diff --git a/notes/demo02/lab.md b/notes/demo02/lab.md deleted file mode 100644 index 8742d5c..0000000 --- a/notes/demo02/lab.md +++ /dev/null @@ -1,12 +0,0 @@ -# Lab - -````{card} - -The lab details are posted on the lab course. - -```{button-link} https://canvas.ubc.ca/courses/66799 -Physics 111 Lab Course -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/demo02/learninglogs.md b/notes/demo02/learninglogs.md deleted file mode 100644 index b6e624e..0000000 --- a/notes/demo02/learninglogs.md +++ /dev/null @@ -1,16 +0,0 @@ -# Learning Logs - -This week's learning log assignment is now posted on Canvas: - -https://canvas.ubc.ca/courses/63995/quizzes/255367 - -````{card} - -This week's learning log assignment is now posted on Canvas. - -```{button-link} https://canvas.ubc.ca/courses/63995/quizzes/255367 -Learning Log #1 -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` diff --git a/notes/demo02/readings.md b/notes/demo02/readings.md deleted file mode 100644 index 019ec25..0000000 --- a/notes/demo02/readings.md +++ /dev/null @@ -1,16 +0,0 @@ -# Readings - -This week the readings assignments are: - - - -````{card} - -If you have access to the eText, click here to access the eText. - -```{button-link} https://portal.mypearson.com -Pearson eText -:type: url -:classes: btn-outline-warning btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/demo02/test.md b/notes/demo02/test.md deleted file mode 100644 index 73e1301..0000000 --- a/notes/demo02/test.md +++ /dev/null @@ -1,13 +0,0 @@ -# Test 1 - -````{card} - -This week you will have your first Test, and it will mostly be on the contents of Chapter 2 and 3. -Remember that Test 1 will be available starting at Thursday at 6:00 PM PDT and will remain available until Saturday at 6:00 PM. -You will have 60 minutes to complete the test. - -```{button-link} https://canvas.ubc.ca/courses/63995/assignments -Test 1 on Canvas - -``` -```` \ No newline at end of file diff --git a/notes/demo02/videos.md b/notes/demo02/videos.md deleted file mode 100644 index 0cdfe4c..0000000 --- a/notes/demo02/videos.md +++ /dev/null @@ -1,196 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -``` -```` - -## Summary of Calculus from Crash Course Physics (Optional but recommended) - -```{dropdown} Derivatives - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -```{dropdown} Integrals - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -## Required Videos - -```{dropdown} 1. Vectors and 2D Motion - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 2. Introduction to Tip-to-Tail Vector Addition, Vectors and Scalars - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0049_lecture_notes_-_introduction_to_tip-to-tail_vector_addition_vectors_and_scalars.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/vectors-and-scalars.html) -``` - -```{dropdown} 3. Introductory Tip-to-Tail Vector Addition Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0008_lecture_notes_-_introduction_to_velocity_and_speed.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/tip-to-tail-vector-addition.html) -``` - -```{dropdown} 4. Introduction to Vector Components - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0052_lecture_notes_-_introduction_to_vector_components.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/vector-components.html) -``` - -```{dropdown} 5. Introduction to Component Vectors and Unit Vectors - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -```{dropdown} 6. Introductory Vector Addition Problem using Component Vectors - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0053_lecture_notes_-_introductory_vector_addition_problem_using_component_vectors_also_0054.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/introductory-vector-addition-problem.html) -``` - -```{dropdown} 7. A Visually Complicated Vector Addition Problem using Component Vectors - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0055_lecture_notes_-_a_visually_complicated_vector_addition_problem_using_component_vectors.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/complicated-vector-addition.html) -``` - -```{dropdown} 8. An Introductory Vector Addition Problem using Unit Vectors - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` -```{dropdown} 9. Introduction to the R Position Vector by way of an Example Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -```{dropdown} 10. Using the R Position Vector to find Velocity and Acceleration - Example Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -```{dropdown} 11. How to use Cardinal Directions with Vectors - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0051_lecture_notes_-_how_to_use_cardinal_directions_with_vectors.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/cardinal-directions.html) -``` - -## Optional Videos - -The videos below are relevant to the subject material, but are not required for Physics 111. - -```{dropdown} 12. Using a Data Table to Make Vector Addition Problems Easier - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/_0053_lecture_notes_-_introductory_vector_addition_problem_using_component_vectors_also_0054.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/data-table.html) - -``` \ No newline at end of file diff --git a/notes/demo03/demo03_summary.md b/notes/demo03/demo03_summary.md deleted file mode 100755 index 432bdfd..0000000 --- a/notes/demo03/demo03_summary.md +++ /dev/null @@ -1,92 +0,0 @@ -# Readings - -This week we will discuss the famous Hamlet soliloquy, also known as Act III Scene I. -Your task is to annotate the words with your commentary, and come to class ready to discuss and act out this scene in your interpretation. - -> To be, or not to be: that is the question: -> -> Whether 'tis nobler in the mind to suffer -> -> The slings and arrows of outrageous fortune, -> -> Or to take arms against a sea of troubles, -> -> And by opposing end them? To die: to sleep; -> -> No more; and by a sleep to say we end -> -> The heart-ache and the thousand natural shocks -> -> That flesh is heir to, 'tis a consummation -> -> Devoutly to be wish'd. To die, to sleep; -> -> To sleep: perchance to dream: ay, there's the rub; -> -> For in that sleep of death what dreams may come -> -> When we have shuffled off this mortal coil, -> -> Must give us pause: there's the respect -> -> That makes calamity of so long life; -> -> For who would bear the whips and scorns of time, -> -> The oppressor's wrong, the proud man's contumely, -> -> The pangs of despised love, the law's delay, -> -> The insolence of office and the spurns -> -> That patient merit of the unworthy takes, -> -> When he himself might his quietus make -> -> With a bare bodkin? who would fardels bear, -> -> To grunt and sweat under a weary life, -> -> But that the dread of something after death, -> -> The undiscover'd country from whose bourn -> -> No traveller returns, puzzles the will -> -> And makes us rather bear those ills we have -> -> Than fly to others that we know not of? -> -> Thus conscience does make cowards of us all; -> -> And thus the native hue of resolution -> -> Is sicklied o'er with the pale cast of thought, -> -> And enterprises of great pith and moment -> -> With this regard their currents turn awry, -> -> And lose the name of action.—Soft you now! -> -> The fair Ophelia! Nymph, in thy orisons -> -> Be all my sins remember'd. -> - -```{dropdown} Benedict Cumberbatch as Hamlet - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -```{dropdown} Mel Gibson as Hamlet - :class-container: sd-shadow-lg - :color: primary -
- -
-``` \ No newline at end of file diff --git a/notes/demo04/demo04_summary.md b/notes/demo04/demo04_summary.md deleted file mode 100644 index 12b3e02..0000000 --- a/notes/demo04/demo04_summary.md +++ /dev/null @@ -1,20 +0,0 @@ -# Lecture - -This week in the lecture we will go through the following worksheet and clicker questions. - -## Video on Drawing Lewis Structures - -
- -
- -## PhET Simulation - - - -## Drawing Molecules with MarvinJS - -More [details about MarvinJS here](https://chemaxon.com/products/marvin-js) - - + + +## Important links for today: + +- \ No newline at end of file diff --git a/notes/setup/install_macOS.md b/notes/setup/install_macOS.md deleted file mode 100644 index bfaeb1b..0000000 --- a/notes/setup/install_macOS.md +++ /dev/null @@ -1,450 +0,0 @@ -(page_install_macOS)= -macOS Software Stack -======================= - - - - - -These instructions will walk you through installing the required software stack for {{ COURSE_CODE }}. -Before starting, ensure that your laptop meets the minimum requirements: - -- Runs a recent version of macOS. The following versions have successfully been setup using the instructions below - - macOS Sonoma (14.2.x), Ventura (13.x) Monterey (12.x), BigSur (11.x). -- Can connect to networks via a wireless connection -- Has at least 25 GB disk space available -- Has at least 4 GB of RAM (more is better, 8GB is recommended) -- Uses a 64-bit CPU -- Is at most 6 years old at the start of the course (4 years old or newer is recommended) -- Student user has full administrative access to the computer - -If your computer does not meet any of the requirements above, please don't just drop the course!! -Let me know first and we can discuss alternate possibilities so you can still take the course. - -```{tip} -Before starting, I suggest updating your Mac to the latest version your laptop can run: - - -``` - -## Installation notes - -```{tip} -These installation notes assume that you are starting with a "fresh" install, and that you don't have any custom installations and setups. -If you have previously installed Python and any related packages, we recommend (but not require) you to uninstall these and follow the instructions below to install and configure them correctly for our course (make sure to also remove any user configuration files and backup them if desired). -``` - -Starting with macOS Catalina, Apple stopped including a pre-installed Python installation on macOS (believe it or not, this is a good thing because the version included was always out of date!). -In order to be able to support you effectively and minimize setup issues and software conflicts, we have written some instructions for all students to install the software stack the same way. - -In all the sections below, if you are presented with the choice to download either a 64-bit (also called x64) or a 32-bit (also called x86) version of the application **always** choose the 64-bit version. -If you purchased a Mac anytime in the last few years, chances are you have an "M1/M2/M3"... Mac, also known as Apple Silicon, and `arm64`. -When given the option, you should choose to download the `arm64` or Apple Silicon versions - if that choice doesn't exist, then you can choose the "Universal" version which will run in "emulated mode", which will result in a slight performance penalty. - -## Table of Contents - - -- [Web browser](#web-browser) -- [Zoom](#zoom) -- [Git and GitHub](#git-and-github) - -- [Python](#python) -- [Visual Studio Code](#visual-studio-code) -- [Terminal](#terminal) - -- [tree](#tree) - - - -## Web browser - -You are welcome to use most modern browsers that have a WebKit or Gecko backend. -[Safari](https://www.apple.com/ca/safari/), [Firefox](https://www.mozilla.org/en-CA/firefox/new/?redirect_source=firefox-com), [Vivaldi](https://vivaldi.com), [Brave](https://brave.com), [Edge](https://www.microsoft.com/en-us/edge) are all recommended. -Google Chrome is not recommended because of the [well-documented privacy and tracking issues with Google](https://www.forbes.com/sites/zakdoffman/2021/03/20/stop-using-google-chrome-on-apple-iphone-12-pro-max-ipad-and-macbook-pro/). - -## Zoom - -We will be using Zoom in this course for all the student hours and you should install the Zoom client locally on your machine. -It is important that you have the most recent version of Zoom installed, as we will be using many of the features that are only available in more recent versions. - -The latest version of Zoom as of Sept 2022 is: `5.16.10 (25689)`. -You can ensure you have the latest version of Zoom by clicking "Check for Updates" as shown in the screenshot below. - -Zoom 'Check for Updates' showing the latest version of Zoom is installed. - -```{important} -Please note that if you have been relying on the "web version" of Zoom that works only in a browser, this will not work for this course! Please make sure to download the Zoom desktop client for your operating system to fully participate in the course. -``` - -## Git and GitHub - -Sign up for a free account at [GitHub.com](https://github.com/) if you don't have one already. -Your GitHub username is important, here's how to find your username: - -Pointing to the top right once you log into GitHub.com to identify your username. - -### Install Git on your computer - -We will be using the command line version of Git. -Some of the Git commands we will use are only available since Git 2.23, so if your Git is older than this version, we ask you to update it using the Xcode command line tools (not all of Xcode), which includes Git. - -```{tip} -To open a new Terminal, find the Terminal app on your computer (`Applications->Utilities->Terminal`) or activate Spotlight and type in Terminal and then enter. -You will need to do this several times in these instructions. -``` - -Open your Terminal and type the following command to install Xcode command line tools: - -``` -xcode-select --install -``` - -After installation, in Terminal type the following to check the version: - -``` -git --version -``` - -You should see something like this (does not have to be the exact same version) if you were successful: - -``` -git version 2.40.0 -``` - -```{note} -If you run into trouble, this is the time to post on {{ FORUM_LINK }} with your error message and ask for help! -``` - -### Configuring Git user info - -Next, we need to configure Git by telling it your name and email. -To do this type the following into the Terminal (the same ones you used to sign up for GitHub): - -``` -git config --global user.name "YOUR NAME HERE" -git config --global user.email YOUR@EMAIL.com -``` - -```{note} -To ensure that you haven't made a typo in any of the above, you can view your global Git configurations by either opening the configuration file by typing `git config --list --global`. You can quit this view by just pressing the `q` key on your keyboard. -``` - -### Create your GitHub "Personal Access Token" - -This is a bit tricky, so please make sure you follow these directions carefully. - -1. Create a Personal Access Token on GitHub.com by clicking this link: https://github.com/settings/tokens/new; make sure to COPY the token that they give you, it is basically a special password that you can use in the Terminal. -Detailed steps are: - -- Log in to GitHub.com, -- Click your picture in the top right, -- Click Settings, -- Click Developer Settings -- Click "Personal access tokens", set the appropriate permissions at the "repo" level (see image below): - -```{figure} setup_images/repo.png ---- -name: PAT_mac ---- -Personal Access Token settings -``` - - - -- Click "Generate new token" -- Save this token somewhere on your computer, you will need it when you clone a **private** repository to your computer. -- Don't share your token with anyone and protect it like it's your password! You will not be able to come back to this page to get your token. If you forget it, or lose it, you can just delete the token and create another one. - -### Clone your first repository on your computer! - -Open a Terminal window, and then run the following command: - -``` -git clone https://github.com/firasm/test.git -``` - -Hopefully, if things work, you should be able to see a new folder created at that location. -We will be talking more about what exactly you did over the next week and a bit, don't worry! - -```{tip} -If after running the code above, you see the error message: - -> fatal: destination path 'test' already exists and is not an empty directory. - -It means that you already attempted a clone before, and there is already a directory called `test` where you are trying to clone this repository. -You will first need to delete that directory to try again. - -Open a Finder window on your computer, navigate to the directory, right click the `test` directory, and then delete the directory. -Alternatively, from the command line you can try: - -> rm -rf test - -which will "remove" the directory called "test". The "-" is to specify additional options: `r` means "recursively" for all the files in the directory, and `f` means "force" which means don't ask me for confirmation after deleting each file and folder. -``` - - - -## Python - -We are now ready to install Python! - -We will be using Python for a large part of the course, and `conda` will be our Python package manager. -We will be using the [Miniconda installer (read more here)](https://docs.conda.io/en/latest/miniconda.html) to install both python and conda at the same time. -Miniconda also provides us with a minimum number of useful packages so installation is quick, and relatively painless. - -### Installing `conda` and python - -The latest Miniconda installer can be downloaded from here: [Miniconda macOS Apple M1 64-bit pkg install](https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.pkg). - -After installation, restart the terminal. -If the installation was successful, you will see `(base)` prepending to your prompt string. -To confirm that `conda` is working, you can check in the Terminal if it's installed and which version was installed: -``` -conda --version -``` -which should return something like this: - -``` -conda 23.11.0 -``` - -```{note} -Note: If you see `zsh: command not found: conda`, try the following>: Open a new Terminal (it should be zsh), then type: `source /Users/YOURUSERNAME/miniconda3/bin/activate` OR `source ~/miniconda3/bin/activate` depending on whether you installed for all users, or just your user (make sure to also change YOURUSERNAME to your username). Then enter the following command `conda init zsh`. The error should now be fixed. -``` - -Next, type the following to ask for the version of Python: -``` -python --version -``` -which should return something like this: - -``` -Python 3.11.5 -``` - -```{note} -Note: If instead you see `Python 2.7.X` you installed the wrong version. Uninstall the Miniconda you just installed (which usually lives in the `/opt` directory), and try the installation again, selecting **Python 3.11** (or higher). -``` - -### Essential Python packages - -`conda` is a Python package manager that can install packages from different online repositories which are called "channels". -A package needs to go through thorough testing before it is included in the default channel, which is good for stability, but also means that new versions will be delayed and fewer packages are available overall. -There is a community-driven effort called the [conda-forge (read more here)](https://conda-forge.org/), which provides more up-to-date packages. -To enable us to access the most recent versions of the Python packages we are going to use, we will add this channel. -To add the conda-forge channel type the following in a Terminal window: - -``` -conda config --add channels conda-forge -``` - -To install packages individually, we need to use the following command: `conda install -c conda-forge ""`. -The part about `conda install` tells the `conda` package manager to install a particular package, and the `-c` part is an extra "option" that tells `conda` to look in the `conda-forge` channel (which usually has the latest updated packages). -Let's install the key packages needed (you will note that we're also specifying certain versions of the package with `= X.Y`). -You should copy and paste each line (one-by-one) below in your Terminal to install the following packages: - -``` -conda install -c conda-forge "black" -conda install -c conda-forge "pandas" -conda install -c conda-forge "seaborn" -conda install -c conda-forge "pre-commit" -``` - -`conda` will show you the packages that will be downloaded, and you may need to press `enter` or `Y` (for yes) to proceed with the installation. -This may take a while to complete. - -```{tip} -We will be installing more Python packages as we go through the course! -``` - -## Visual Studio Code - -The open-source text editor Visual Studio Code (VS Code) is both a powerful text editor and a full-blown Python IDE (interactive development environment), which we will use for more complex analysis. -You can download and install the macOS version of VS Code from the VS code website [https://code.visualstudio.com/download](https://code.visualstudio.com/download). -Once the download is finished, click "Open with Archive utility", and move the extracted VS Code application from "Downloads" to "Applications". -Make sure you are able to open VS Code by clicking on the application. - -### VS Code extensions - -The real magic of VS Code is in the extensions that let you add languages, debuggers, and tools to your installation to support your specific workflow. -We will install some VS Code extensions to help us with our workflows. -From within VS Code you can open up the [Extension Marketplace (read more here)](https://code.visualstudio.com/docs/editor/extension-gallery) to browse and install extensions by clicking on the Extensions icon in the Activity Bar indicated in the figure below. - -Pointing to the left sidebar to where extensions can be installed. - -To install an extension, you simply search for it in the search bar, click the extension you want, and then click "Install". -There are extensions available to make almost any workflow or task you are interested in more efficient! -Here we are interested in setting up VS Code as a Python IDE. -To do this, search for and install the following extensions: - -- **Python** (by Microsoft) -- **Python Debugger** (by Microsoft) -- **autoDocString** (by Nils Werner) -- **Python Indent** (by Kevin Rose) -- **Black Formatter** (for formatting, linting) -- **Markdown Table Formatter** (helps format markdown tables) -- **Rainbow CSV** (for colouring columns in CSV files) -- **indent-rainbow** (for helping you see indents) -- **markdownlint** (markdown linting and style checking extension) - -Pointing to the Python extension by Microsoft in the list of extensions. Click 'Install' - - - -## Terminal - -The Terminal is already pre-installed on macOS as long as you're running macOS Big Sur or later (macOS 11.x)! - -You can proceed to spice up your Terminal a bit! - -### Install Ohmyzsh to get Terminal colours, and highlighting - -Install `Ohmyzsh` to add Terminal colours, highlighting and other cool features. - -Oh My Zsh is installed by running the following command in your Terminal: - -``` -sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" -``` - -You may now customize your Terminal with themes (see [screenshots of themes here](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes)) by [following the directions here](https://github.com/ohmyzsh/ohmyzsh#selecting-a-theme). -Selecting a theme is optional, the default one is pretty good as it is! - - - -### Configure VS Code to launch from the Terminal - -1. Launch VS Code. -2. Open the Command Palette (⇧⌘P ; Shift+Command+P). -3. Type 'shell command' to find the "Shell Command: Install 'code' command in PATH" command. -4. Hit Enter -5. Restart the Terminal for the new $PATH value to take effect. - -You can open files in VS Code from the Terminal! -Alternatively, just type `code .` in any folder to start editing files in that folder. - -You can test that VS Code is installed and can be opened from Terminal by restarting Terminal and typing the following command in a Terminal: - -``` -code --version -``` - -you should see something like this if you were successful: - -``` -1.85.2 -8b3775030ed1a69b13e4f4c628c612102e30a681 -arm64 -``` - -If this does **not** work for you, try it again: - -1. Restart VS Code. -2. Open the Command Palette (⇧⌘P ; Shift+Command+P). -3. Type 'shell command' to find the "Shell Command: Uninstall 'code' command from PATH". -4. Hit Enter. -5. Type 'shell command' to find the "Shell Command: Install 'code' command from PATH". -6. You might need to enter in your Mac's admin password. - -If this **still* does not work, then you should ask a TA for help, but if you're feeling brave, -[manual install instructions are here - remember to use the `zsh` files](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line) steps as well. - -### Setting VS Code as the default editor - -To make programs run from the Terminal (such as `git`) use VS Code by default, we will modify `~/.z_profile`. First, open it using VS Code: - -``` -code ~/.z_profile -``` - -```{note} -If you see any existing lines in your `~/.z_profile` related to a previous Python installation, please remove them. -``` - -Paste the following lines in the new file that opens up: - -``` -# Set the default editor for programs launch from Terminal -EDITOR="code --wait" -VISUAL=$EDITOR # Use the same value as for "EDITOR" in the line above -``` - -Then save the file and exit VS Code. - -> Most Terminal programs will read the `EDITOR` environmental variable when determining which editor to use, but some read `VISUAL`, so we're setting both to the same value. - -## Tree - -"Tree is a recursive directory listing program that produces a depth indented listing of files." -This is very useful to explore your directory and file structure to figure out which files are where. - -You can install the `tree` package using this command: - -`conda install -c conda-forge tree` - - - -After this, you're all done! - -## Attributions - -* [Harvard CS109](http://cs109.github.io/2015/) -* [UBC STAT 545](http://stat545.com/packages01_system-prep.html#mac-os-system-prep) licensed under the [CC BY-NC 3.0](https://creativecommons.org/licenses/by-nc/3.0/legalcode). -* [Software Carpentry](https://software-carpentry.org/) - -```{important} -These instructions have been adapted and remixed from the original version provided by the UBC-Vancouver [MDS Install stack](https://ubc-mds.github.io/resources_pages/installation_instructions/) under a CC-BY-SA 4.0 license. They were originally written by [Anmol Jawandha](https://github.com/Anmol6) but have since been updated by Firas Moosvi, Joel Ostblom, Tomas Beuzen, Rodolfo Lourenzutti, & Tiffany Timbers, and others. -``` \ No newline at end of file diff --git a/notes/setup/install_ubuntu.md b/notes/setup/install_ubuntu.md deleted file mode 100644 index a31b7a7..0000000 --- a/notes/setup/install_ubuntu.md +++ /dev/null @@ -1,643 +0,0 @@ -(page_install_ubuntu)= -Ubuntu Software Stack -======================= - - - - - - -```{important} -This guide has been (lightly) adapted from the UBC-Vancouver [MDS Install stack](https://ubc-mds.github.io/resources_pages/installation_instructions/) under a CC-BY-SA 4.0 license. -``` - -These instructions will walk you through installing the required software stack for the UBC Master of Data Science program. Before starting, ensure that your laptop meets our program requirements: - - - runs one of the following operating systems: macOS 10.15.X (Catalina), Ubuntu 20.04, Windows 10 Professional, Enterprise or Education; version 2004. - - **Windows 10 Home is not sufficient** as not all the software required for the program can be installed on that OS. [Click here to download Windows 10 Education for free from UBC.](https://it.ubc.ca/software-downloads) - - When installing Ubuntu, checking the box "Install third party..." will (among other things) install proprietary drivers, which can be helpful for wifi and graphics cards. -- can connect to networks via a wireless connection -- has at least 50 GB disk space available -- has at least 8 GB of RAM -- uses a 64-bit CPU -- is at most 6 years old at the start of the program (4 years old or newer is recommended) -- uses English as the default language -- student user has full administrative access to the computer - -**Students' whose laptops do not meet the requirements specified above will not be able to receive technical assistance from the MDS team in troubleshooting installation issues.** - -## Table of Contents - -- [UBC Student Email](#ubc-student-email) -- [Web browser](#web-browser) -- [Visual Studio Code](#visual-studio-code) -- [GitHub](#github) -- [Git](#git) -- [Python, Conda, and JupyterLab](#python-conda-and-jupyterlab) -- [R, IRkernel, and RStudio](#r-irkernel-and-rstudio) -- [LaTeX](#latex) -- [PostgreSQL](#postgresql) -- [Docker](#docker) -- [VS Code extensions](#vs-code-extensions) -- [Improving the bash configuration](#improving-the-bash-configuration) -- [Post-installation notes](#post-installation-notes) - -## Installation notes - -If you have already installed Git, Latex, or any of the R or Python related packages -please uninstall these and follow the instructions below to reinstall them -(make sure to also remove any user configuration files and backup them if desired). -In order to be able to support you effectively -and minimize setup issues and software conflicts, -we require all students to install the software stack the same way. - -In all the sections below, -if you are presented with the choice to download either a 64-bit (also called x64) -or a 32-bit (also called x86) version of the application **always** choose the 64-bit version. - -Once you have completed these installation instructions, -make sure to follow the post-installation notes at the end -to check that all software is setup correctly. - -## UBC Student Email - -Please sign up for a UBC Student Email. This account will also grant you access to a range of UBC services, including Microsoft Teams and OneDrive. To do so navigate to [https://it.ubc.ca/services/email-voice-internet/ubc-student-email-service](https://it.ubc.ca/services/email-voice-internet/ubc-student-email-service) and follow the instructions under "Get Started". - -## Web browser - -In MDS we will be using many tools that work most reliably on Google Chrome and Firefox (including our online quiz software), so we recommend that you use one of these browsers. - -- Firefox comes preinstalled with Ubuntu, so there is not need to download anything. -- To install Chrome, go to [https://www.google.com/chrome/](https://www.google.com/chrome/), click on "Download Chrome" choose the deb-file, download it to your computer and click on the downloaded file to install it. - -> Note that if you select "open with" and try to open the file directly with the Ubuntu Software app instead of downloading it first, the software app might complain that the file is not supported. - -## Visual Studio Code - -The open-source text editor Visual Studio Code (VS Code) is both a powerful text editor and a full-blown Python IDE, which we will use for more complex analysis. You can install VS Code either via the [Snap store/Ubuntu software app through this link](https://snapcraft.io/code) or via the downloadable deb-file from the VS code website [https://code.visualstudio.com/download](https://code.visualstudio.com/download). The getting started instructions are here: [https://code.visualstudio.com/docs/?dv=linux64_deb](https://code.visualstudio.com/docs/?dv=linux64_deb). - -You can test that VS code is installed and can be opened from Terminal by restarting terminal and typing the following command: - -``` -code --version -``` - -you should see something like this if you were successful: - -``` -1.47.0 -d5e9aa0227e057a60c82568bf31c04730dc15dcd -x64 -``` - -## GitHub - -In MDS we will use the publicly available [GitHub.com](https://github.com/) as well as an Enterprise version of GitHub hosted here at UBC, [GitHub.ubc.ca](https://github.ubc.ca). Please follow the set-up instructions for both below. - -### GitHub.com - -Sign up for a free account at [GitHub.com](https://github.com/) if you don't have one already. - -### GitHub.ubc.ca - -To add you to the MDS organization on [Github.ubc.ca](https://github.ubc.ca) we need you to login to [Github.ubc.ca](https://github.ubc.ca) using your CWL credentials. - -This step is required for -- being able to store your work -- all homework submission and grading -- working collaboratively - -## Git - -We will be using the command line version of Git as well as Git through RStudio and JupyterLab. Some of the Git commands we will use are only available since Git 2.23, so if you're Git is older than this version, we ask you to update it using the following command: - -``` -sudo apt update -sudo apt install git -``` - -You can check your git version with the following command: - -``` -git --version -``` - -### Configuring Git user info - -Next, we need to configure Git by telling it your name and email. To do this type the following into the terminal (replacing Jane Doe and janedoe@example.com, with your name and email (the same you used on GitHub), respectively): - -``` -git config --global user.name "Jane Doe" -git config --global user.email janedoe@example.com -``` - -> Note: to ensure that you haven't made a typo in any of the above, you can view your global Git configurations by either opening the configuration file in a text editor (e.g. via the command `code ~/.gitconfig`) or by typing `git config --list --global`. - -### Setting VS Code as the default editor - -To make programs run from the terminal (such as `git`) use VS Code by default, we will modify the bash configuration file `~/.bashrc`. First, open it using VS Code: - -``` -code ~/.bashrc -``` - -> Note: If you see any existing lines in your `~/.bashrc` -> related to a previous Python or R installation, -> please remove these. - -Append the following lines: - -``` -# Set the default editor for programs launch from terminal -EDITOR="code --wait" -VISUAL=$EDITOR # Use the same value as for "EDITOR" in the line above -``` - -Then save the file and exit VS Code. - -> Most terminal programs will read the `EDITOR` environmental variable when determining which editor to use, but some read `VISUAL`, so we're setting both to the same value. - -## Python, Conda, and JupyterLab - -### Python and Conda - -We will be using Python for a large part of the program, and `conda` as our Python package manager. To install Python and the `conda` package manager, we will use the [Miniconda platform (read more here)](https://docs.conda.io/en/latest/miniconda.html), for which the [Python 3.8 64-bit version can be downloaded here](https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh). - -Once the download is finished, open Terminal and execute the following commands: -``` -bash path/to/file -``` - -> Note: most often this file is downloaded to the `Downloads` directory, and thus the command will look like this: -> ->``` ->bash Downloads/Miniconda3-latest-Linux-x86_64.sh ->``` - -The instructions for the installation will then appear: - -(1) Press Enter. -(2) Once the licence agreement shows, you can press space scroll down, or press `q` to skip reading it. -(3) Type `yes` and press enter to accept the licence agreement. -(4) Press enter to accept the default installation location. -(5) Type `yes` and press enter to instruct the installer to run `conda init`, which makes `conda` available from the terminal/shell. - -After installation, restart the terminal. If the installation was successful, you will see `(base)` prepending to your prompt string. To confirm that `conda` is working, you can ask it which version was installed: -``` -conda --version -``` -which should return something like this: - -``` -conda 4.8.3 -``` - -Next, type the following to ask for the version of Python: -``` -python --version -``` -which should return something like this: - -``` -Python 3.8.3 -``` - -> Note: If instead you see `Python 2.7.X` you installed the wrong version. Uninstall the Miniconda you just installed (which usually lives in the `/home/` directory), and try the installation again, selecting **Python 3.8**. - -## Essential Python packages - -`conda` installs Python packages from different online repositories which are called "channels". -A package needs to go through thorough testing before it is included in the default channel, -which is good for stability, -but also means that new versions will be delayed and fewer packages are available overall. -There is a community-driven effort called the [conda-forge (read more here)](https://conda-forge.org/), -which provides more up to date packages -To enable us to access the most up to date version of the Python packages we are going to use, -we will add the more up to date channel, -To add the conda-forge channel by typing the following in the terminal: - -``` -conda config --add channels conda-forge -``` - -To install packages individually, we can now use the following command: `conda install `. Let's install the key packages needed for the start of our program: - -``` -conda install \ - "jupyterlab=2.*" \ - "numpy=1.*" \ - "pandas=1.*" \ - "flake8=3.*" \ - "black=19.*" -``` - -`conda` will show you the packages that will be downloaded, -and you can press enter to proceed with the installation. -If you want to answer `yes` by default and skip this confirmation step, -you can replace `conda install` with `conda install -y`. - -> Note: we will use many more packages than those listed above across the MDS program, however we will manage these using virtual environments (which you will learn about in DSCI 521: Platforms for Data Science). - -## JupyterLab setup - -We will be using the Jupytext Python package and the JupyterLab git extension to facilitate using Jupyter notebooks with Git & GitHub. Install them via the following commands: - -``` -conda install nodejs=10.* -pip install --upgrade jupyterlab-git -conda install jupytext=1.* -jupyter lab build -``` - -To test that your JupyterLab installation is functional, you can type `jupyter lab` into a terminal, which should open a new tab in your default browser with the JupyterLab interface. -To exit out of JupyterLab you can click `File -> Shutdown`, -or go to the terminal from which you launched JupyterLab and hold `Ctrl` while pressing `c` twice. - -## R, IRkernel, and RStudio - -R is another programming language that we will be using a lot in the MDS program. We will use R both in Jupyter notebooks and in RStudio. - -### R - -The version of R available in the default Ubuntu repositories (`3.6.*`) is older than the one we use in MDS (`4.*`). To obtain the latest R `4.*` packages, we need to add a new repository which is maintained directly by the r-project. To do this, first add the key for this repository by typing the following: - -``` -sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 -``` - -Then add the URL to the repository: - -``` -sudo apt-add-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' -``` - -Next, install `r-base` and `r-base-dev` (useful for compiling R packages from source): - -``` -sudo apt install r-base r-base-dev -``` - -After installation, type the following in a terminal to ask for the version: -``` -R --version -``` - -You should see something like this if you were successful: - -``` -R version 4.0.2 (2020-06-22) -- "Taking Off Again" -Copyright (C) 2020 The R Foundation for Statistical Computing -Platform: x86_64-pc-linux-gnu (64-bit) - -R is free software and comes with ABSOLUTELY NO WARRANTY. -You are welcome to redistribute it under the terms of the -GNU General Public License versions 2 or 3. -For more information about these matters see -https://www.gnu.org/licenses/. -``` - -> Note: Although it is possible to install R through conda, we highly recommend not doing so. In case you have already installed R using conda you can remove it by executing `conda uninstall r-base`. - -### RStudio - -Download the Ubuntu 18/Debian 10 Desktop version of RStudio Preview from [https://rstudio.com/products/rstudio/download/preview/](https://rstudio.com/products/rstudio/download/preview/). Open the file and follow the installer instructions. - -> Note that there is not yet an official RStudio version for Ubuntu 20.04, so it is recommended to use the Ubuntu 18 version. Also note that if you select "open with" and try to open the file directly with the Ubuntu Software app instead of downloading it first, the software app might complain that the file is not supported. - -To see if you were successful, try opening RStudio by clicking on its icon or typing `rstudio` in a terminal. It should open and look something like this picture below: - - - -> Note that since we installed RStudio directly from a deb file rather than from a repository or a snap package, it will not be updated when we run `sudo apt upgrade` and not automatically as for snap packages. Instead, RStudio will notify you of any available updates when the program is launched. - -### Essential R packages - -The `tidyverse` R package (and some others) have external dependencies on Ubuntu outside of R. We need to install these first before we install such R packages: - -``` -sudo apt install libcurl4-openssl-dev libssl-dev libxml2-dev -``` - -Next, install the key R packages needed for the start of MDS program, -by opening up RStudio and -typing the following into the R console inside RStudio: - -``` -install.packages(c('tidyverse', 'blogdown', 'xaringan', 'renv', 'usethis', 'devtools')) -``` - -> Note: we will use many more packages than those listed above across the MDS program, however we will manage these using the `renv` package manager (which you will learn about in DSCI 521: Platforms for Data Science). - -### IRkernel - -The `IRkernel` package is needed to make R work in Jupyter notebooks. To enable this kernel in the notebooks, install it and run the setup via the following two commands: - -``` -install.packages('IRkernel') -IRkernel::installspec() -``` - -> Note: If you see an error message saying "jupyter-client has to be installed...", -> close RStudio and run the following line from your terminal instead `R -e "IRkernel::installspec()"`. - -To see if you were successful, try running JupyterLab and check if you have a working R kernel. To launch JupyterLab, type the following in a terminal: - -``` -jupyter lab -``` - -A browser should have launched and you should see a page that looks like the screenshot below. Now click on "R" notebook (circled in red on the screenshot below) to launch an JupyterLab with an R kernel. - - - -Sometimes a kernel loads, but doesn't work as expected. To test whether your installation was done correctly now type `library(tidyverse)` in the code cell and click on the run button to run the cell. If your R kernel works you should see something like the image below: - - - -To improve the experience of using R in JupyterLab, -we will add an extension that allows us to setup keyboard shortcuts for inserting text -(thanks to former MDS student Ryan Homer for developing this extension!). -By default, -it creates shortcuts for inserting two of the most common R operators: `<-` and `%>%`. -Run the following from terminal to install the extension: - -``` -jupyter labextension install @techrah/text-shortcuts -jupyter lab build -``` - -To check that the extension is working, -open JupyterLab, -launch an R notebook, -and try inserting the operators by pressing `Alt` + `-` or `Shift` + `Ctrl` + `m`, respectively. - -## LaTeX - -We will install the lightest possible version of LaTeX and it's necessary packages as possible so that we can render Jupyter notebooks and R Markdown documents to html and PDF. If you have previously installed LaTeX, please uninstall it before proceeding with these instructions. - -First, open RStudio and run the following commands to install the `tinytex` package and setup `tinytex`: - -``` -install.packages('tinytex') -tinytex::install_tinytex() -``` - -The above is all we need to have LaTeX work with R Markdown documents, however for Jupyter we need to add the TinyTex executables to our `PATH` and install several more packages (`PATH` is a collection of directories which contain the available executable programs on your computer). - -To append the TinyTex executables to our `PATH` we need to edit our `.bashrc` file. The TinyTex executables are usually installed in `$HOME/bin`. Thus, add the lines below to the bottom of your `.bashrc` file (which you can open by `code $HOME/.bashrc`) and save the file: - -``` -# Append TinyTex executables to the path -export PATH="$PATH:$HOME/bin" -``` - -When you launch a new terminal instance, this directory will have been added to your path (you can check this by running `echo $PATH` in the terminal. - -Next, install the additional LaTeX packages needed for Jupyter by pasting the following into the new terminal instance and press enter: - -``` -tlmgr install eurosym \ - adjustbox \ - caption \ - collectbox \ - enumitem \ - environ \ - fp \ - jknapltx \ - ms \ - parskip \ - pgf \ - rsfs \ - tcolorbox \ - titling \ - trimspaces \ - ucs \ - ulem \ - upquote -``` - -To test that your latex installation is working with jupyter notebooks, -launch `jupyter lab` from a terminal and open either a new notebook -or the same one you used to test IRkernel above. -Go to `File -> Export notebook as... -> Export Notebook to PDF`. -If the PDF file is created, -your LaTeX environment is set up correctly. -You can also check by typing the following to ask for the version of latex: - -``` -latex --version -``` - -You should see something like this if you were successful: - -``` -pdfTeX 3.14159265-2.6-1.40.21 (TeX Live 2020) -kpathsea version 6.3.2 -Copyright 2020 Han The Thanh (pdfTeX) et al. -There is NO warranty. Redistribution of this software is -covered by the terms of both the pdfTeX copyright and -the Lesser GNU General Public License. -For more information about these matters, see the file -named COPYING and the pdfTeX source. -Primary author of pdfTeX: Han The Thanh (pdfTeX) et al. -Compiled with libpng 1.6.37; using libpng 1.6.37 -Compiled with zlib 1.2.11; using zlib 1.2.11 -Compiled with xpdf version 4.02 -``` - -## PostgreSQL - -We will be using PostgreSQL as our database management system. To install PostgreSQL type the following command: - -``` -sudo apt install postgresql postgresql-contrib -``` - -By default, this installation creates a new user called `postgres`, -which is the only one with permission to open the databases. -We will see how to set this up for other users later in the program, -but for now run the following to confirm that your installation was successful: - -``` -sudo su -c psql postgres -``` - -The above should yield the prompt to change to what is shown below: - -``` -psql (12.2 (Ubuntu 12.2-4)) -Type "help" for help. - -postgres=# -``` - -> Note: to exit from Postgres type `exit`, or press `ctrl` + `d`. - -## Docker - -You will use Docker to create reproducible, sharable and shippable computing environments for your analyses. For this you will need a Docker account. You can [sign up for a free one here](https://store.docker.com/signup?next=%2F%3Fref%3Dlogin). - -After signing-up, you also need to install Docker **CE** for Ubuntu. Install the stable version by following the installation instructions using the ["Install using the repository" methods found here](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository), including the subheadings "Set up the repository" and "Install Docker engine". - -Next, [follow the Linux post installation steps here](https://docs.docker.com/engine/install/linux-postinstall/) so that you can run Docker without typing `sudo`, and confirm that docker is working by following the verification instructions on that same page. - -## VS Code extensions - -The real magic of VS Code is in the extensions that let you add languages, debuggers, and tools to your installation to support your specific workflow. From within VS Code you can open up the [Extension Marketplace (read more here)](https://code.visualstudio.com/docs/editor/extension-gallery) to browse and install extensions by clicking on the Extensions icon in the Activity Bar indicated in the figure below. - - - -To install an extension, you simply search for it in the search bar, click the extension you want, and then click "Install". There are extensions available to make almost any workflow or task you are interested in more efficient! Here we are interested in setting up VS Code as a Python IDE. To do this, search for and install the following extensions: - -- Python (everything Python: notebooks, debugging, linting, formatting, etc.) -- markdownlint (markdown linting and style checking extension) -- GitLens (powerful extension that extends VS Code's native git capabilities) -- Docker (easily use Docker from VS Code) -- (Optional) Material Theme and/or Predawn Theme Kit (additional colour themes to choose from) -- (Optional) Material Icon Theme (great-looking custom file icons!) -- (Optional) Bracket Pair Colorizer 2 (add colour to help distinguish your brackets: (), [], {}) - -[This video tutorial](https://www.youtube.com/watch?v=06I63_p-2A4) is an excellent introduction to using VS Code in Python. - -## Improving the bash configuration - -To improve your experience using bash, -we recommend appending a few lines to the end of your bash configuration file. -This is optional, -but makes it easier to use the TAB key for autocompletion -and improves how bash handles the command history -(we will talk more about these topics during class). -First, -open the configuration file: - -``` -code ~/.bashrc -``` - -Then paste the following at the end of the file -(make sure not to overwrite any existing lines) -and save it afterwards: - -``` -# TAB completion configuration -# TAB completion ignores case -bind "set completion-ignore-case on" -# Require only one instead of two TAB presses before showing matches -bind "set show-all-if-ambiguous on" -# If there are multiple matches for completion, cycle through them with TAB -bind 'TAB':menu-complete -# Perform partial completion on the first Tab press, -# only start cycling full results on the second Tab press -bind "set menu-complete-display-prefix on" - -# History configuration -# Cycle through history based on characters already typed on the line -bind '"\e[A":history-search-backward' -bind '"\e[B":history-search-forward' -# Append to the history file, don't overwrite it. -shopt -s histappend -# Write commands to history one-by-one right after they are executed -# instead of all together when the terminal is closed. -# Make new terminals see all commands run in currently open terminals and -# prepend a newline to the prompt string to separate it from the last command's output -PROMPT_COMMAND='history -a; echo' -# Increase history size -HISTSIZE=50000 -HISTFILESIZE=50000 -``` - -## Post-installation notes - -You have completed the installation instructions, well done 🙌! -We have created a script to help you check that your installation was successful, -and to provide instructions for how you can troubleshoot any issues. -To run this script, -please execute the following command from your terminal. - -``` -bash <(curl -Ss https://raw.githubusercontent.com/UBC-MDS/UBC-MDS.github.io/master/resources_pages/check-setup-mds.sh) -``` - -The output from running the script will look something like this: - -```` -# MDS setup check 0.1.0 - -If a program or package is marked as MISSING, -this means that you are missing the required version of that program or package. -Either it is not installed at all or the wrong version is installed. -The required version is indicated with a number and an asterisk (*), -e.g. 4.* means that all versions starting with 4 are accepted (4.0.1, 4.2.5, etc). - -You can run the following commands to find out which version -of a program or package is installed (if any): -``` -name_of_program --version # For system programs -conda list # For Python packages -R -q -e "installed.packages()[,c(Package, Version)]" # For R packages -``` - -Checking program and package versions... - -## Operating system -Operating System: Ubuntu 20.04 -Architecture: x86-64 -Kernel: Linux 5.4.0-28-generic - -## System programs -OK psql 12.3 -MISSING rstudio=1.* -OK R 4.0.2 (2020-06-22) -- "Taking Off Again" -OK python 3.8.3 -OK conda 4.8.3 -OK bash 4-pc-linux-gnu) -OK git 2.27.0 -OK make 4.3 -OK latex 3.14159265-2.6-1.40.21 (TeX Live 2020) -OK tlmgr 55369 (2020-06-01 02:32:00 +0200) -MISSING docker=19.* -MISSING code=1.* - -## Python packages -MISSING jupyterlab=2.* -MISSING numpy=1.* -MISSING pandas=1.* -OK flake8=3.7.9 -MISSING black=19.* -MISSING nodejs=10.* -OK jupytext=1.3.4 -MISSING jupyterlab-git=0.* -MISSING jupyterlab PDF-generation failed. Check that latex and jupyterlab are marked OK above. - -## R packages -OK tidyverse=1.3.0 -OK blogdown=0.20 -OK xaringan=0.16 -OK renv=0.11.0 -OK IRkernel=1.1.1 -OK tinytex=0.25 -OK rmarkdown PDF-generation was successful - -This output and additional configuration details -have been saved to the file check-setup-mds.log in this directory. -```` - -As you can see at the end of the output, -a log file is saved in your current directory. -We might ask you to upload this file -if we need to troubleshoot your installation, -so that we can help you more effectively. -If any of your packages are marked as "MISSING" -you will need to figure out what is wrong and possibly reinstall them. -Once all packages are marked as "OK" -we will ask you to submit this log file, -so that we can confirm that your installation was successful. -Details on where to submit will be provided later. - -> Note that in general you should be careful running scripts unless they come from a trusted source as in this case (just like how you should be careful when downloading and installing programs on your computer). - -## Attributions - -* [Harvard CS109](http://cs109.github.io/2015/) -* [UBC STAT 545](http://stat545.com/packages01_system-prep.html#mac-os-system-prep) licensed under the [CC BY-NC 3.0](https://creativecommons.org/licenses/by-nc/3.0/legalcode). -* [Software Carpentry](https://software-carpentry.org/) diff --git a/notes/setup/install_windows.md b/notes/setup/install_windows.md deleted file mode 100644 index 2c6f4ca..0000000 --- a/notes/setup/install_windows.md +++ /dev/null @@ -1,516 +0,0 @@ -(page_install_windows)= -Windows Software Stack -======================= - - - - - -These instructions will walk you through installing the required software stack for {{ COURSE_CODE }}. -Before starting, ensure that your laptop meets the minimum requirements: - -- Runs the latest version of Windows 11 available for your system. - - Currently enrolled UBC students with a valid CWL account [qualify for one license of Windows 11 Education](https://it.ubc.ca/services/desktop-print-services/software-licensing/windows-education). -- Can connect to networks via a wireless connection. -- Has at least 25 GB disk space available. -- Has at least 4 GB of RAM (more is recommended). -- Uses a 64-bit CPU. -- Is at most 6 years old at the start of the course (4 years old or newer is recommended). -- Student user has full administrative access to the computer. - -If your computer does not meet any of the requirements above, please don't just drop the course!! -Let me know first and we can discuss alternate possibilities so you can still take the course. - - -```{tip} -Before starting, I suggest updating your Windows operating system to the latest version your laptop can run: - -[See here](https://support.microsoft.com/en-us/windows/update-windows-3c5ae7fc-9fb6-9af1-1984-b5e0412c556a) on how to update your Windows 11 machine to the latest version. -``` - -## Installation notes - -Unless you really know what you are doing, if you have already installed Git, Conda, or any of the Python related packages below, I **strongly** advise you to please uninstall these and follow the instructions below to re-install and configure them correctly (make sure to also remove any user configuration files and backup them if desired). -In order to be able to support you effectively and minimize setup issues and software conflicts, we suggest students to install the software stack the same way (even though there are better ways). - -In all the sections below, if you are presented with the choice to download either a 64-bit (also called x64) or a 32-bit (also called x86) version of the application **always** choose the 64-bit version. - -Once you have completed these installation instructions, make sure to follow the post-installation notes at the end to check that all software is setup correctly. - -## Table of Contents - - -- [Zoom](#zoom) -- [Web browser](#web-browser) - -- [Visual Studio Code](#visual-studio-code) -- [Terminal](#terminal-gitbash) -- [Python](#python) -- [Configuring VS Code extensions](#vscode-extensions) -- [Git and GitHub](#git-and-github) -- [Tree](#tree) - - - - -## Web browser - -You are welcome to use most modern browsers that have a WebKit or Gecko backend. -[Safari](https://www.apple.com/ca/safari/), [Firefox](https://www.mozilla.org/en-CA/firefox/new/?redirect_source=firefox-com), [Vivaldi](https://vivaldi.com), [Brave](https://brave.com), [Edge](https://www.microsoft.com/en-us/edge) are all recommended. -Google Chrome is not recommended because of the [well-documented privacy and tracking issues with Google](https://www.forbes.com/sites/zakdoffman/2021/03/20/stop-using-google-chrome-on-apple-iphone-12-pro-max-ipad-and-macbook-pro/). - -## Zoom - -We will be using Zoom in this course for the classes, as well as the labs, and student hours. -It is *very* important that you have the most recent version of Zoom installed, as we will be using many of the features that are only available in more recent versions. - -The latest version of Zoom as of Sept 2022 is: `5.11.10 (102279)`. -You can ensure you have the latest version of Zoom by clicking "Check for Updates" as shown in the screenshot below (on a Windows machine, your screenshot will look slightly different). - -Zoom 'Check for Updates' showing the latest version of Zoom is installed. - -```{important} -Please note that if you have been relying on the "web version" of Zoom that works only in a browser, this will not work for this course! -Please make sure to download the Zoom desktop client for your operating system to fully participate in the course. -``` - - - -## GitHub.com account - -Sign up for a free account at [GitHub.com](https://github.com/) if you don't have one already. -Your GitHub username is important, here's how to find your username: - -Pointing to the top right once you log into GitHub.com to identify your username. - -## Visual Studio Code - -The open-source text editor Visual Studio Code (VS Code) is both a powerful text editor and a full-blown Python IDE, which we will use for more complex analysis. -You can download and install the Windows version of VS Code from the VS code website [https://code.visualstudio.com/download](https://code.visualstudio.com/download). -Once the download is finished, double click it to open and follow the installation instructions. -Make sure you are able to open VS Code by clicking on the application. - -## Terminal (GitBash) - -Unfortunately, one of the major problems with using the Windows operating system is that the "Command Prompt" that comes with the operating system is severely deficient. -No worries though, luckily most of the tools we use in this course are open source, so the community has worked hard to shore up deficiencies in the Microsoft ecosystem (until Windows subsystem for Linux is a more mature product). - -The replacement for the Command Prompt we will use in this course is called "GitBash". -The latest version of GitBash for Windows is: `2.43.0`. - -```{attention} -"GitBash" is relatively old software, but it is very reliable and works very well. -If you are feeling brave and want to setup `zsh` (the next generation Terminal, with many improvements) on Windows, you can [try these instructions here](https://dev.to/zinox9/installing-zsh-on-windows-37em). -Note that these instructions are experimental and support from the teaching team is limited. But if you can get it to work or run into any issues, let me know! -I hope to adopt zsh on windows fully next time I teach this course. -``` - -Briefly, we will be using the Bash shell to interact with our computers via a command line interface, and Git to keep a version history of our files and upload to/download from to GitHub. - -Go to and download the windows version of GitBash. -After the download has finished, run the installer and **accept the default configuration for all pages except for the following**: - -- On the **Choosing the default editor used by Git** page, select "Use Visual Studio Code as Git's default editor" from the drop-down menu' -- *Optional* On the **Select Components** page, check "On the Desktop" under "Additional icons". - - - -```{note} -If you wish to pin Git Bash to the taskbar, you need to search for the program in the start menu, right click the entry and select "Pin to taskbar". If you instead first launch the program and pin it by right clicking on the taskbar icon, Git Bash will open with the wrong home directory (`/` instead of `/c/users/$USERNAME`. -``` - -```{note} -After installation, test if you were successful by opening the GitBash program. -Below is a picture of the Git Bash icon on the Desktop and an opened instance of the Git Bash terminal (we will often refer to this as just the "Terminal"). -From now on, all commands should be entered into the GitBash program (not Anaconda Command Prompt, or Command Prompt, or PowerShell etc...). -``` - - - -In the terminal, type the following to check which version of Bash you just installed: - -``` -bash --version -``` - -The output should look similar to this: - -``` -GNU bash, version 4.4.23(1)-release (x86_64-pc-sys) -Copyright (C) 2019 Free Software Foundation, Inc. -License GPLv3+: GNU GPL version 3 or later - -This is free software; you are free to change and redistribute it. -There is NO WARRANTY, to the extent permitted by law. -``` - -> If you tried to paste the above into the Git Bash terminal, you will have noticed that `Ctrl+V` does not work in Git Bash. Instead you need to right click and select "Paste" or use the `Shift+Insert` shortcut. To copy from the Git Bash terminal you simply select the text you want and it is copied automatically. - -> Via right click you can also reach the settings menu where you can configure Git Bash to your preferences, a couple of tips would be to check "Mouse -> Clicks place command line cursor" and change the font to something more legible, e.g. Consolas ("Text -> Select"). - -Let's also check which version of git was installed: - -``` -git --version -``` - -``` -git version 2.32.0.windows.1 -``` - -> *Optional* One annoyance with our current terminal setup is that the word `(base)` is not on the same row as the rest of the prompt string (the part with `your_name@your_computer`. To fix this we can edit the `.bash_profile` configuration file to indicate that we do not want a newline at the beginning of the prompt string. Open up the configuration file using VS Code by typing the following command into a terminal: -> -> ``` -> code "/c/Program Files/Git/etc/profile.d/git-prompt.sh" -> ``` -> -> Delete the line that reads the following (it should be line 13): -> -> ``` -> PS1="$PS1"'\n' # new line -> ``` -> -> Click to save the file, -> when VS Code prompts you that the saving failed, -> click "Retry as Admin" and then "Yes". -> That's it! -> Now if you launch a new terminal instance, -> you will see `(base)` on the same line as the rest of the prompt string as in the screenshot below. -> -> - -## Python - -We will be using Python for this course, and `conda` will be our Python package manager. - -### Installing `conda` and python - -To install Python and the `conda` package manager, we will use the [Miniconda platform (read more here)](https://docs.conda.io/en/latest/miniconda.html), for which the [**Python 3.11** (or higher) 64-bit version can be downloaded here](https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe). -Miniconda also provides us with a minimum number of useful packages so installation is quick, and relatively painless. - -After the download has finished, run the installer and accept the default configuration for all pages. - -```{warning} -Make sure to check the box to add Miniconda to the PATH. There is a big scary warning that says this is "Not Recommended" ; you can ignore that warning, and make sure that checkbox is clicked! -``` - -After the installation is complete, open the Start Menu and search for the program called "Anaconda Prompt (miniconda3)". -When this opens you will see a prompt similar to `(base) C:\Users\your_name`. -Type the following to check that your Python installation is working: - -``` -python --version -``` - -which should return something like this: - -``` -Python 3.11.5 -``` - -> If instead you see `Python 2.7.X` you installed the wrong version. -Follow [these instructions](https://docs.anaconda.com/anaconda/install/uninstall) to delete this installation and try the installation again, selecting **Python 3.11** (or higher). - -### Integrating Python with the Git Bash terminal - -```{warning} -This part is very important!!! -``` - -To avoid having to open the separate Anaconda Prompt every time we want to use Python, we can make it available from the (Git Bash) terminal, which is what we will be using most of the time. -To set this up, open the "Anaconda Prompt (miniconda3)" again and type: - -``` -conda init bash -``` - -You will see that this modified a few configuration files, which makes `conda` visible to the terminal. Close all open terminal windows and launch a new one, you should now see that the prompt string has changed to include the word `(base)` as in the screenshot below: - - - -If you type - -``` -python --version -``` - -you should now see the same output as above (you may see a higher version of python, that's fine: - -``` -Python 3.11.5 -``` - -> Note that if you want to run Python interactively from the Git Bash terminal, you need to prepend the `winpty` command, so the full command would be `winpty python` (if you run this, note that you can exit the Python prompt by typing `exit()`). Running just `python` works on other setups, but will freeze the Git Bash terminal. - -Let's also check the version of the `conda` package manager. If you type - -``` -conda --version -``` - -you should see something like this - -``` -conda 23.11.0 -``` - -> *Optional* One annoyance with our current terminal setup is that the word `(base)` is not on the same row as the rest of the prompt string (the part with `your_name@your_computer`. To fix this we can edit the `.bash_profile` configuration file to indicate that we do not want a newline at the beginning of the prompt string. Open up the configuration file using VS Code by typing the following command into a terminal: -> -> ``` -> code "/c/Program Files/Git/etc/profile.d/git-prompt.sh" -> ``` -> -> Delete the line that reads the following (it should be line 13): -> -> ``` -> PS1="$PS1"'\n' # new line -> ``` -> -> Click to save the file, -> when VS Code prompts you that the saving failed, -> click "Retry as Admin" and then "Yes". -> That's it! -> Now if you launch a new terminal instance, -> you will see `(base)` on the same line as the rest of the prompt string as in the screenshot below. -> - -Decorative - -### Essential Python packages - -`conda` installs Python packages from different online repositories which are called "channels". -A package needs to go through thorough testing before it is included in the default channel, which is good for stability, but also means that new versions will be delayed and fewer packages are available overall. -There is a community-driven effort called the [conda-forge (read more here)](https://conda-forge.org/), which provides more up-to-date packages. -To enable us to access the most recent versions of the Python packages we are going to use, we will add this channel. -To add the conda-forge channel type the following in a Terminal window: - -``` -conda config --add channels conda-forge -``` - -To install packages individually, we need to use the following command: `conda install -c conda-forge ""`. -The part about `conda install` tells the `conda` package manager to install a particular package, and the `-c` part is an extra "option" that tells `conda` to look in the `conda-forge` channel (which usually has the latest updated packages). -Let's install the key packages needed (you will note that we're also specifying certain versions of the package with `= X.Y`). -You should copy and paste each line below in your Terminal to install the following packages: - -``` -conda install -c conda-forge "black" -conda install -c conda-forge "pandas" -conda install -c conda-forge "seaborn" -conda install -c conda-forge "pre-commit" -``` - -`conda` will show you the packages that will be downloaded, and you may need to press `enter` or `Y` (for yes) to proceed with the installation. -We are specifying that we should use the "conda-forge" source because it typically has more recent and updated package versions. -This may take a while to complete. - -## VSCode extensions - -The real magic of VS Code is in the extensions that let you add languages, debuggers, and tools to your installation to support your specific workflow. -Now that we have installed all our other Data Science tools, we can install the VS Code extensions that work really well with them. -From within VS Code you can open up the [Extension Marketplace (read more here)](https://code.visualstudio.com/docs/editor/extension-gallery) to browse and install extensions by clicking on the Extensions icon in the Activity Bar indicated in the figure below. - -Pointing to the left sidebar to where extensions can be installed. - -To install an extension, you simply search for it in the search bar, click the extension you want, and then click "Install". -There are extensions available to make almost any workflow or task you are interested in more efficient! -Here we are interested in setting up VS Code as a Python IDE. -To do this, search for and install the following extensions: - -- **Python** (by Microsoft) -- **Python Debugger** (by Microsoft) -- **autoDocString** (by Nils Werner) -- **Python Indent** (by Kevin Rose) -- **Black Formatter** (for formatting, linting) -- **Markdown Table Formatter** (helps format markdown tables) -- **Rainbow CSV** (for colouring columns in CSV files) -- **indent-rainbow** (for helping you see indents) -- **markdownlint** (markdown linting and style checking extension) - -Pointing to the VS Code for Python extension by Microsoft in the list of extensions. Click 'Install' - - - -## Git and GitHub - -We will use the publicly available [GitHub.com](https://github.com/). - -You should already have your GitHub.com username, you will need that for the next few steps. - -### Install Git on your computer - -Although Git and GitBash are two separate programs, Git is packaged with GitBash and so you've already installed it. -Time to configure it. - -### Configuring Git user info - -Next, we need to configure Git by telling it your name and email. -To do this type the following into the Terminal (the same ones you used to sign up for GitHub): - -``` -git config --global user.name "YOUR NAME HERE" -git config --global user.email YOUR@EMAIL.com -``` - -```{note} -To ensure that you haven't made a typo in any of the above, you can view your global Git configurations by either opening the configuration file in a text editor (e.g. via the command `code ~/.gitconfig`) or by typing `git config --list --global`. -``` - -### Create your GitHub "Personal Access Token" - -This is a bit tricky, so please make sure you follow these directions carefully. - -1. Create a Personal Access Token on GitHub.com by clicking this link: https://github.com/settings/tokens/new; make sure to COPY the token that they give you, it is basically a special password that you can use in the Terminal. Detailed steps are: - -- Log in to GitHub.com, -- Click your picture in the top right, -- Click Settings, -- Click Developer Settings -- Click "Personal access tokens", set the appropriate permissions at the "repo" level (see image below): - -```{figure} setup_images/repo.png ---- -name: PAT_windows ---- -Personal Access Token settings -``` - - - -- Click "Generate new token" -- Save this token somewhere on your computer, you will need it when you clone a **private** repository to your computer. -- Don't share your token with anyone and protect it like it's your password! You will not be able to come back to this page to get your token. If you forget it, or lose it, you can just delete the token and create another one. - -### Clone your first repository on your computer! - -Open a GitBash Terminal window, and then run the following command: - -``` -git clone https://github.com/firasm/test.git -``` - -Hopefully, if things work, you should be able to see a new folder created at that location. -We will be talking more about what exactly you did over the next week and a bit, don't worry! - -```{tip} -If after running the code above, you see the error message: - -> fatal: destination path 'test' already exists and is not an empty directory. - -It means that you already attempted a clone before, and there is already a directory called `test` where you are trying to clone this repository. -You will first need to delete that directory to try again. - -Open an Explorer window on your computer, navigate to the directory, right click the `test` directory, and then delete the directory. -Alternatively, from the command line you can try: - -> rm -rf test - -which will "remove" the directory called "test". The "-" is to specify additional options: `r` means "recursively" for all the files in the directory, and `f` means "force" which means don't ask me for confirmation after deleting each file and folder. -``` - -### Launch VS Code from GitBash - -You can launch many windows programs from the Bash terminal, e.g. to launch VS Code that we installed previously, you would type in `code`, let's use this to check the version of vscode that we installed: - -``` -code --version -``` - -``` -1.71 -e4503b30fc78200f846c62cf8091b76ff5547662 -x64 -``` - -### Setting VS Code as the default editor - -To make programs run from the terminal (such as `git`) use VS Code by default, we will modify `~/.bash_profile`. First, open it using VS Code: - -``` -code ~/.bash_profile -``` - -> Note: If you see any existing lines in your `~/.bash_profile` related to a previous Python or R installation, please remove these. - -Append the following lines: - -``` -# Set the default editor for programs launch from terminal -EDITOR="code --wait" -VISUAL=$EDITOR # Use the same value as for "EDITOR" in the line above -``` - -Then save the file and exit VS Code. - -> Most terminal programs will read the `EDITOR` environmental variable when determining which editor to use, but some read `VISUAL`, so we're setting both to the same value. - -## Tree - -From the [Tree for Windows](http://gnuwin32.sourceforge.net/packages/tree.htm) page, "Tree is a recursive directory listing program that produces a depth indented listing of files." -This is very useful to explore your directory and file structure to figure out which files are where. - -Unfortunately, `Tree` is not trivial to install on Windows, but it is definitely worth the 2-3 minutes it takes to install it. -The steps [in detail are outlined here (with screenshots)](https://dev.to/flyingduck92/add-tree-to-git-bash-on-windows-10-1eb1). - -In brief, the steps are: - -1. Download the [Tree binaries](http://downloads.sourceforge.net/gnuwin32/tree-1.5.2.2-bin.zip) - -2. Unzip the file, and navigate to the `bin` directory, and find `tree.exe`. - -3. Move or copy the `tree.exe` file to this location: `C:\Program Files\Git\usr\bin`. - -4. Restart GitBash and type in `tree`. - -If things work, then you're all done! - - - -## Attributions -* [Harvard CS109](http://cs109.github.io/2015/) -* [UBC STAT 545](http://stat545.com/packages01_system-prep.html#mac-os-system-prep) licensed under the [CC BY-NC 3.0](https://creativecommons.org/licenses/by-nc/3.0/legalcode). -* [Software Carpentry](https://software-carpentry.org/) -* [Oracle - How do I set or change the PATH system variable?](https://www.java.com/en/download/help/path.xml) -* [Numerical Methods - Getting started](https://clouds.eos.ubc.ca/~phil/numeric/python.html) - -```{important} -These instructions have been adapted and remixed from the original version provided by the UBC-Vancouver [MDS Install stack](https://ubc-mds.github.io/resources_pages/installation_instructions/) under a CC-BY-SA 4.0 license. They were originally written by [Anmol Jawandha](https://github.com/Anmol6) but have since been updated by Firas Moosvi, Joel Ostblom, Tomas Beuzen, Rodolfo Lourenzutti, & Tiffany Timbers, and others. -``` - diff --git a/notes/setup/setup_images/GitHubcreatePAT.gif b/notes/setup/setup_images/GitHubcreatePAT.gif deleted file mode 100644 index 81154ec..0000000 Binary files a/notes/setup/setup_images/GitHubcreatePAT.gif and /dev/null differ diff --git a/notes/setup/setup_images/GitHubcreatePAT_red.gif b/notes/setup/setup_images/GitHubcreatePAT_red.gif deleted file mode 100644 index 3dbcb6a..0000000 Binary files a/notes/setup/setup_images/GitHubcreatePAT_red.gif and /dev/null differ diff --git a/notes/setup/setup_images/RStudio-ubuntu.png b/notes/setup/setup_images/RStudio-ubuntu.png deleted file mode 100644 index 27b2e7c..0000000 Binary files a/notes/setup/setup_images/RStudio-ubuntu.png and /dev/null differ diff --git a/notes/setup/setup_images/RStudio.png b/notes/setup/setup_images/RStudio.png deleted file mode 100644 index 4a452f3..0000000 Binary files a/notes/setup/setup_images/RStudio.png and /dev/null differ diff --git a/notes/setup/setup_images/add-conda-env-to-ps1.png b/notes/setup/setup_images/add-conda-env-to-ps1.png deleted file mode 100644 index ed6cee4..0000000 Binary files a/notes/setup/setup_images/add-conda-env-to-ps1.png and /dev/null differ diff --git a/notes/setup/setup_images/env-vars-new-user-var.png b/notes/setup/setup_images/env-vars-new-user-var.png deleted file mode 100644 index ab15a8e..0000000 Binary files a/notes/setup/setup_images/env-vars-new-user-var.png and /dev/null differ diff --git a/notes/setup/setup_images/extract-make-path.png b/notes/setup/setup_images/extract-make-path.png deleted file mode 100644 index 8b00097..0000000 Binary files a/notes/setup/setup_images/extract-make-path.png and /dev/null differ diff --git a/notes/setup/setup_images/extract-make.png b/notes/setup/setup_images/extract-make.png deleted file mode 100644 index f759175..0000000 Binary files a/notes/setup/setup_images/extract-make.png and /dev/null differ diff --git a/notes/setup/setup_images/gitbash.png b/notes/setup/setup_images/gitbash.png deleted file mode 100644 index 36ee49e..0000000 Binary files a/notes/setup/setup_images/gitbash.png and /dev/null differ diff --git a/notes/setup/setup_images/github_account.png b/notes/setup/setup_images/github_account.png deleted file mode 100644 index 1134e31..0000000 Binary files a/notes/setup/setup_images/github_account.png and /dev/null differ diff --git a/notes/setup/setup_images/jupyter_lab.png b/notes/setup/setup_images/jupyter_lab.png deleted file mode 100644 index e4154a1..0000000 Binary files a/notes/setup/setup_images/jupyter_lab.png and /dev/null differ diff --git a/notes/setup/setup_images/jupyter_lab_r_kernel.png b/notes/setup/setup_images/jupyter_lab_r_kernel.png deleted file mode 100644 index e5d1837..0000000 Binary files a/notes/setup/setup_images/jupyter_lab_r_kernel.png and /dev/null differ diff --git a/notes/setup/setup_images/jupyter_lab_r_kernel2.png b/notes/setup/setup_images/jupyter_lab_r_kernel2.png deleted file mode 100644 index 815c772..0000000 Binary files a/notes/setup/setup_images/jupyter_lab_r_kernel2.png and /dev/null differ diff --git a/notes/setup/setup_images/new-user-var-values.png b/notes/setup/setup_images/new-user-var-values.png deleted file mode 100644 index c57ead7..0000000 Binary files a/notes/setup/setup_images/new-user-var-values.png and /dev/null differ diff --git a/notes/setup/setup_images/psql-windows.png b/notes/setup/setup_images/psql-windows.png deleted file mode 100644 index cee5c30..0000000 Binary files a/notes/setup/setup_images/psql-windows.png and /dev/null differ diff --git a/notes/setup/setup_images/remove-newline-from-ps1.png b/notes/setup/setup_images/remove-newline-from-ps1.png deleted file mode 100644 index c468528..0000000 Binary files a/notes/setup/setup_images/remove-newline-from-ps1.png and /dev/null differ diff --git a/notes/setup/setup_images/repo.png b/notes/setup/setup_images/repo.png deleted file mode 100644 index 492f4a3..0000000 Binary files a/notes/setup/setup_images/repo.png and /dev/null differ diff --git a/notes/setup/setup_images/sys-props-env-vars.png b/notes/setup/setup_images/sys-props-env-vars.png deleted file mode 100644 index 0256f49..0000000 Binary files a/notes/setup/setup_images/sys-props-env-vars.png and /dev/null differ diff --git a/notes/setup/setup_images/updatemacOS.gif b/notes/setup/setup_images/updatemacOS.gif deleted file mode 100644 index 7f7c031..0000000 Binary files a/notes/setup/setup_images/updatemacOS.gif and /dev/null differ diff --git a/notes/setup/setup_images/vscode-as-git-editor.png b/notes/setup/setup_images/vscode-as-git-editor.png deleted file mode 100644 index f73ceb5..0000000 Binary files a/notes/setup/setup_images/vscode-as-git-editor.png and /dev/null differ diff --git a/notes/setup/setup_images/vscode.png b/notes/setup/setup_images/vscode.png deleted file mode 100644 index fb9b2bc..0000000 Binary files a/notes/setup/setup_images/vscode.png and /dev/null differ diff --git a/notes/setup/setup_images/vscode_python.png b/notes/setup/setup_images/vscode_python.png deleted file mode 100644 index 9bd1e84..0000000 Binary files a/notes/setup/setup_images/vscode_python.png and /dev/null differ diff --git a/notes/setup/setup_images/zoom.png b/notes/setup/setup_images/zoom.png deleted file mode 100644 index d868d2c..0000000 Binary files a/notes/setup/setup_images/zoom.png and /dev/null differ diff --git a/notes/setup/stack.md b/notes/setup/stack.md deleted file mode 100644 index c636670..0000000 --- a/notes/setup/stack.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -myst: - substitutions: - key1: "macOS Sonoma 14.2.1" ---- -(page_tech_stack)= -Tech Stack -======================= - -For any computer science (or data science) course, several tools and software packages are needed for this course. -These tools are not usually included on your computer, and if they are, some configuration is necessary. -This page links out to a guide (depending on your operating system) to install the "Tech Stack" for {{ COURSE_CODE }}. -A "Tech Stack" is the complete set of tools and technologies needed to accomplish a particular task, in this case, Data Analytics. - -As you go through the install guides, remember that perhaps the two most important things you will learn in this course is how to troubleshoot things and achieve familiarity and proficiency with your computer. -Be patient, read things carefully, do not be afraid to try things, it's unlikely you will do anything to irreversibly break your computer! -Almost everything you do (you're on your own if you decide to take a hammer to your laptop!) can be undone, don't be afraid to ask your peers, TAs, and the instructor on {{ FORUM_LINK }}. - -This is an exciting time for you as you begin your Software Development journey! - -## Install the Software Stack - -Below are links to the software installation guide used for {{ COURSE_CODE }} for the three operating systems that are currently supported. - -- [macOS](page_install_macOS) -- [Windows](page_install_windows) -- [Ubuntu](page_install_ubuntu) - -## Attribution - -```{important} -These instructions have been adapted and remixed from the original version provided by the UBC-Vancouver [MDS Install stack](https://ubc-mds.github.io/resources_pages/installation_instructions/) under a CC-BY-SA 4.0 license. They were originally written by [Anmol Jawandha](https://github.com/Anmol6) but have since been updated by Firas Moosvi, Joel Ostblom, Tomas Beuzen, Rodolfo Lourenzutti, & Tiffany Timbers, and others. -``` \ No newline at end of file diff --git a/notes/week01/class1A.md b/notes/week01/class1A.md deleted file mode 100644 index 4cc2c2f..0000000 --- a/notes/week01/class1A.md +++ /dev/null @@ -1,22 +0,0 @@ -# Class Meeting 1A - -Below are the slides from today's class embedded. -Feel free to download them to keep them locally, or leave them archived here and just bookmark them. -We will leave the website open even after the course is over for a reasonable number of years. - - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec01Intro.pdf) - -## Important links for today: - -- [Canvas](https://canvas.ubc.ca/courses/130127) -- [PrairieLearn](https://canvas.ubc.ca/courses/130127/external_tools/48751) -- [Markdown Tutorial](https://commonmark.org/help/tutorial/) - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week01/class1B.md b/notes/week01/class1B.md deleted file mode 100644 index d6d761d..0000000 --- a/notes/week01/class1B.md +++ /dev/null @@ -1,157 +0,0 @@ -# Class Meeting 1B - -Today we will be learning about the Terminal! - -
- -
- -CommandPrompt - -CommandPrompt - -## Announcements - -[Download the (logistics) Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec02Terminal.pdf) - -## Introduction to the Terminal (Command Line) - -If you would like some additional notes and a much deeper explanation of the command line (also known as the Terminal), I suggest the notes from [Software Carpentry](https://swcarpentry.github.io/shell-novice/)! -They are excellent. - -In particular, I suggest "Introducing the shell", "Navigating Files and Directories", and "Working with Files and Directories" - -### What is the Command Line? - -The **command line** is the text interface to the computer that accepts commands that the computer will execute. -These commands include: - -- starting programs -- navigating directories and manipulating files -- searching, sorting, and editing text files -- system and environment configuration - -### Why learn command line? - -The command line is the text interface to the computer. -Understanding the command line allows you to interact with the computer in ways that you often cannot with the graphical user interface (GUI). - -The command line is commonly used for scripting and automation of tasks and when accessing remote systems. -It will also be useful to run programs that make use of the command line (eg. github). - -### Why use command line? - -The command line is part of the operating system (OS), which is software that manages your computer including all devices and programs. - -- Common operating systems include Windows, Mac OS, and Linux/Unix. -- Some commands will be OS specific - -You might be wondering why we would ever prefer command line over using the graphical user interface (GUI). -- Certain tools may only be available to command line. -- Sometimes command line is faster. - -### Command Line on Windows - -The command line on Windows dates back to the original Microsoft operating system called DOS (Disk Operating System) in 1981. - -This command line interface is still part of all modern Windows operating systems and is accessible as the "Command Prompt". - -**I am requiring you use GitBash instead of the default Windows Command Prompt.** - -### Windows Terminal - -This is what the GitBash "Terminal" looks like. From here on out, whenever we say "Terminal", we mean "GitBash on Windows", "Terminal on macOS and Ubuntu" - -CommandPrompt - -- The directory separator is a forward slash `/` for Macs/Ubuntu, and the opposite pointing slash on Windows `\` -- However if you use GitBash, this should preserve your sanity and you should be able to use forward slash on Windows as well -- In fact, many of the macOS/Ubuntu commands will also work in GitBash, but for completeness we will also share the other commands - -Image source: [Git for windows](https://gitforwindows.org) - -### Mac OS Command Line - -The command line for Mac OS uses the same commands as Linux. It can be opened using Finder then Utilities then Terminal. - -CommandPrompt - -Alternatively, we could type Cmd + spacebar, then type “Terminal" and press ENTER. - -### Entering Commands - -Enter a command at a prompt. The prompt may be a > or a $ or customized by the user. - -Press ENTER to execute the command. - -Commands are case-insensitive on both Mac/Linux and Windows. -Running commands CommandPrompt - -Here are some useful Terminal Commands - -- [`cd`](https://man7.org/linux/man-pages/man1/cd.1p.html) : change directory -- [`pwd`](https://man7.org/linux/man-pages/man1/pwd.1.html) : print working directory -- [`mkdir`](https://man7.org/linux/man-pages/man1/mkdir.1.html): make directory -- [`mkdir -p`](https://man7.org/linux/man-pages/man1/mkdir.1.html): make directory and create (p)arent directories if they do not exist -- [`ls`](https://man7.org/linux/man-pages/man1/ls.1.html): list directory contents -- [`rm`](https://man7.org/linux/man-pages/man1/rm.1.html): Delete a file -- [`rm -r`](https://man7.org/linux/man-pages/man1/rm.1.html): Delete a directory -- [`touch`](https://man7.org/linux/man-pages/man1/touch.1.html): create an empty file with a specific name - -### Special Commands - -These are commands that will require some extra configuration to use. -In this workspace, we've set them up for you already, but just be warned, these will not be available by default on all machines. - -- [`tree`](https://linux.die.net/man/1/tree) : print out a directory tree view of files and folders -- `code`: edit the file in the VS Code editor - - -### Learning Intentions: Terminal - -By the end of class, and after deliberate practice you should be able to: - -- Define command line and list some of its uses -- Explain the purpose of an operating system -- Know how to open the command line window on macOS and Windows -- Enter commands in the Terminal and stop them -- Define: file system, folder, file -- Explain the difference between an absolute and relative path -- Use command line shortcuts to save time -- Be able to cancel a command (Ctrl+C) - -## Tips and Tricks with the Terminal - -- Use the `pwd` command to find out where you are in the Terminal at any point! - -- Use "Up" and "Down" arrow keys to cycle through previously used commands. - - This is a huge time saver! - -- Use Tab completion!! - - Press tab to see available options - -- Use `*` to autocomplete partial matches - -### Conclusion - -- The command line is the text interface to the computer that accepts commands that the computer will execute including running programs, manipulating files, and running scripts. - -- The command line allows for automation and more control than may be available in the user interface. It may also be the only way to interact with the machine if connecting via SSH. - -- The command environment allows for redirecting the standard input and output using input/output redirection and pipes. - -- You need to **PRACTICE PRACTICE PRACTICE** working in the Terminal: to get yourself used to it, I suggest not using the Finder/Explorer on your computer and use the Terminal for everything. - - - `open` will open a file in the default application on macOS. - - `open .` will open the file in Finder. - - `explorer.exe .` will open the folder in Explorer - -## Guide to your operating system (Optional) - -For macOS users, [here's a video](https://www.youtube-nocookie.com/embed/egK5BKEn87c) that shows you a little about some features on your computer. - -https://youtu.be/RX160bcMFuA - -## Guide to the operating system for Windows 10 users - -For Windows 10 users, [here's a video](https://www.youtube-nocookie.com/embed/RX160bcMFuA) that shows you a little about some features on your computer. \ No newline at end of file diff --git a/notes/week01/images/Terminal.png b/notes/week01/images/Terminal.png deleted file mode 100644 index 81c570d..0000000 Binary files a/notes/week01/images/Terminal.png and /dev/null differ diff --git a/notes/week01/images/running_commands.png b/notes/week01/images/running_commands.png deleted file mode 100644 index 4e5d26a..0000000 Binary files a/notes/week01/images/running_commands.png and /dev/null differ diff --git a/notes/week01/videos.md b/notes/week01/videos.md deleted file mode 100644 index e674e07..0000000 --- a/notes/week01/videos.md +++ /dev/null @@ -1,70 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. - -```{dropdown} -:open: - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0007_lecture_notes_-_displacement_versus_distance.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/introduction-to-displacement.html) - -``` - -```{dropdown} -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0008_lecture_notes_-_introduction_to_velocity_and_speed.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/introduction-to-velocity-and-speed.html) - -``` - -```{dropdown} - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0009_lecture_notes_-_average_velocity_example_problem_with_three_velocities.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/average-velocity-example-problem-with-three-velocities.html) - -``` - -```{dropdown} - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0010_lecture_notes_-_example_problem_-_velocity_and_speed_are_different.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/example-problem-velocity-and-speed-are-different.html) - -``` - -```{dropdown} - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0011_lecture_notes_-_understanding_walking_and_graphing_position_as_a_function_of_time.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/understanding-and-walking-graphs-of-position-as-a-function-of-time.html) - -``` - -```{dropdown} - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0012_lecture_notes_-_example_problem_-_finding_necessary_pole_position_speed.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/example-problem-finding-average-speed-for-pole-position-ndash-not-as-easy-as-you-think.html) - -``` \ No newline at end of file diff --git a/notes/week02/Untitled.ipynb b/notes/week02/Untitled.ipynb deleted file mode 100644 index ff78054..0000000 --- a/notes/week02/Untitled.ipynb +++ /dev/null @@ -1,91 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "e5b54578-7c6a-4878-af1f-6c5fc116e305", - "metadata": {}, - "outputs": [], - "source": [ - "def is_prime(number):\n", - " \"\"\"Check if a number is a prime number.\"\"\"\n", - " if number <= 1:\n", - " return False\n", - " elif number == 2:\n", - " return True\n", - " elif number % 2 == 0:\n", - " return False\n", - " else:\n", - " # Check for factors up to the square root of the number\n", - " for i in range(3, int(number**0.5) + 1, 2):\n", - " if number % i == 0:\n", - " return False\n", - " return True" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "609dcd87-a079-46e5-8063-d53404523941", - "metadata": {}, - "outputs": [], - "source": [ - "p = [-50,10,50,17,19,11,541]" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "a09bd645-ae4f-42dc-ac19-338f4e4bcc80", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n", - "False\n", - "False\n", - "True\n", - "True\n", - "True\n", - "True\n" - ] - } - ], - "source": [ - "for n in p:\n", - " print(is_prime(n))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d6d84710-19b1-49ec-9e0f-9a7c6388806a", - "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.10.2" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notes/week02/class2A.ipynb b/notes/week02/class2A.ipynb deleted file mode 100644 index 74f517f..0000000 --- a/notes/week02/class2A.ipynb +++ /dev/null @@ -1,3336 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - }, - "user_expressions": [] - }, - "source": [ - "# Class 2A: Review of Programming in Python I\n", - "\n", - "We will begin soon!\n", - "\n", - "\n", - "\n", - "
\n", - "
\n", - "
\n", - " Photo by Christina Morillo from Pexels\n", - "
\n", - "\n", - "[Download the (logistics) Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec03PythonReview.pdf)\n", - "\n", - "
\n", - " Firas Moosvi\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - }, - "tags": [] - }, - "source": [ - "**Note: Some images may look slightly different than yours as the software gets more polished and icons/user interfaces change, but this should give you a general gist of the essential things.**\n", - "\n", - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Part 1: Introduction (30 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Outline:" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "- Part 1: Review of Python\n", - " - Basic datatypes\n", - " - Lists and tuples\n", - " - Break (5 min)\n", - " - String methods\n", - " - Dictionaries\n", - " - Conditionals" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "\n", - "\n", - "## Datatypes in Python\n", - "\n", - "Python has several data types available.\n", - "The diagram below [from Geeks for Geeks](https://www.geeksforgeeks.org/python-data-types/) shows a nice summary of how the datatypes are classified, and examples of each.\n", - "You'll notice that some types are in a class of their own (`dict`, `set`, `bool`) whereas other ones are similar but have distinguishing features (`list`/`tuple`/`str` and `int`/`float` etc...).\n", - "\n", - "" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Common built-in Python data types\n", - "\n", - "| English name | Type name | Description | Example |\n", - "| :--- | :--- | :--- | :--- |\n", - "| integer | `int` | positive/negative whole numbers | `42` |\n", - "| floating point number | `float` | real number in decimal form | `3.14159` |\n", - "| boolean | `bool` | true or false | `True` |\n", - "| string | `str` | text | `\"I Can Has Cheezburger?\"` |\n", - "| list | `list` | a collection of objects - mutable & ordered | `['Ali','Xinyi','Miriam']` |\n", - "| tuple | `tuple` | a collection of objects - immutable & ordered | `('Thursday',6,9,2018)` |\n", - "| dictionary | `dict` | mapping of key-value pairs | `{'name':'DSCI','code':511,'credits':2}` |\n", - "| none | `NoneType` | represents no value | `None` |" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Variables and Values\n", - "\n", - "- A **value** is a piece of data that a computer program works with such as a number or text. \n", - "- There are different **types** of values: `42` is an integer and `\"Hello!\"` is a string. \n", - "- A **variable** is a name that refers to a value. \n", - " - In mathematics and statistics, we usually use variables names like $x$ and $y$. \n", - " - In Python, we can use any word as a variable name (as long as it starts with a letter and is not a [reserved word](https://docs.python.org/3.3/reference/lexical_analysis.html#keywords) in Python such as `for`, `while`, `class`, `lambda`, etc.). \n", - "- And we use the **assignment operator** `=` to assign a value to a variable.\n", - "\n", - "- See the [Python 3 documentation](https://docs.python.org/3/library/stdtypes.html) for a summary of the standard built-in Python datatypes. \n", - "- See [Think Python (Chapter 2)](http://greenteapress.com/thinkpython/html/thinkpython003.html) for a discussion of variables, expressions and statements in Python." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Numeric Types" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "x = 42.5" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "float" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5\n" - ] - } - ], - "source": [ - "x = 5\n", - "print(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "x=5\n", - "x-2" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [], - "source": [ - "pi = 3.14159" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3.14159\n" - ] - } - ], - "source": [ - "print(pi)" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "float" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(pi)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Arithmetic Operators\n", - "\n", - "The syntax for the arithmetic operators are:\n", - "\n", - "| Operator | Description |\n", - "| :---: | :---: |\n", - "| `+` | addition |\n", - "| `-` | subtraction |\n", - "| `*` | multiplication |\n", - "| `/` | division |\n", - "| `**` | exponentiation |\n", - "| `//` | integer division |\n", - "| `%` | modulo |\n", - "\n", - "Let's apply these operators to numeric types and observe the results." - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "15" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "1 + 2 + 3 + 4 + 5" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.30000000000000004" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "0.1 + 0.2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "```{tip}\n", - "From Firas: This is floating point arithmetic. For an explanation of what's going on, [see this tutorial](https://docs.python.org/3/tutorial/floatingpoint.html).\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "6.28318" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2 * 3.14159" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1024" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2**10" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "int" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(2**10)" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1024.0" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2.0**10" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [], - "source": [ - "int_2 = 2" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [], - "source": [ - "float_2 = 2.0" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [], - "source": [ - "float_2_again = 2." - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "53.5" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "107 / 2" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "53" - ] - }, - "execution_count": 29, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "107 // 2 # \"integer division\" - always rounds down" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "101 % 2 # \"101 mod 2\", or the remainder when 101 is divided by 2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Strings\n", - "\n", - "- Text is stored as a type called a string. \n", - "- We think of a string as a sequence of characters. \n", - "- We write strings as characters enclosed with either:\n", - " - single quotes, e.g., `'Hello'` \n", - " - double quotes, e.g., `\"Goodbye\"`\n", - " - triple single quotes, e.g., `'''Yesterday'''`\n", - " - triple double quotes, e.g., `\"\"\"Tomorrow\"\"\"`" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [], - "source": [ - "my_name = \"Firas Moosvi\"" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Firas Moosvi\n" - ] - } - ], - "source": [ - "print(my_name)" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(my_name)" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [], - "source": [ - "course = 'CPSC 203'" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CPSC 203\n" - ] - } - ], - "source": [ - "print(course)" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 44, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(course)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If the string contains a quotation or apostrophe, we can use double quotes or triple quotes to define the string." - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [], - "source": [ - "sentence = \"It's a rainy day.\"" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "It's a rainy day.\n" - ] - } - ], - "source": [ - "print(sentence)" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "str" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(sentence)" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [], - "source": [ - "saying = '''They say: \n", - "\"It's a rainy day!\"'''" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "They say: \n", - "\"It's a rainy day!\"\n" - ] - } - ], - "source": [ - "print(saying)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Sequence Type\n", - "\n", - "This datatype contains three subtypes and serves as a good way to \"hold/store stuff\" - a container.\n", - "\n", - "Each subtype has their own unique distinguishing features but they can all hold items of any type (and multiple types).\n", - "\n", - "Below are the main differences between lists, tuples, and sets:\n", - "\n", - "- `list`: items are ordered, and **can** be edited, changed after insertion.\n", - "- `set`: items are unique, but not ordered. Items cannot be replaced or changed, but can be removed or added.\n", - "- `tuple`: items are ordered, but cannot be replaced or changed once created.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": {}, - "outputs": [], - "source": [ - "mylist = ['one','two','apples','three','apples',600.50, 50, 'banana']" - ] - }, - { - "cell_type": "code", - "execution_count": 75, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{50, 600.5, 'apples', 'banana', 'one', 'three', 'two'}" - ] - }, - "execution_count": 75, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "set(mylist)" - ] - }, - { - "cell_type": "code", - "execution_count": 76, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "('one', 'two', 'apples', 600.5)" - ] - }, - "execution_count": 76, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mytuple = ('one','two','apples', 600.5)\n", - "\n", - "mytuple" - ] - }, - { - "cell_type": "code", - "execution_count": 78, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "('one', 'two', 'apples', 600.5, 'blagreenck')" - ] - }, - "execution_count": 78, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mytuple +('blagreenck',)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Sets\n", - "\n", - "- Another built-in Python data type is the `set`, which stores an _un-ordered_ list of _unique_ items." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{2, 3, 5, 11}" - ] - }, - "execution_count": 154, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s = {2,3,5,11}\n", - "s" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 155, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "{1,2,3} == {3,2,1}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 156, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "[1,2,3] == [3,2,1]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{2, 3, 5, 11}" - ] - }, - "execution_count": 159, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "s.add(2) # does nothing\n", - "s" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "s[0]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Above: throws an error because elements are not ordered." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Boolean\n", - "\n", - "- The Boolean (`bool`) type has two values: `True` and `False`. " - ] - }, - { - "cell_type": "code", - "execution_count": 50, - "metadata": {}, - "outputs": [], - "source": [ - "the_truth = True" - ] - }, - { - "cell_type": "code", - "execution_count": 51, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], - "source": [ - "print(the_truth)" - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "bool" - ] - }, - "execution_count": 52, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(the_truth)" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": {}, - "outputs": [], - "source": [ - "lies = False" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n" - ] - } - ], - "source": [ - "print(lies)" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "bool" - ] - }, - "execution_count": 55, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(lies)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Comparison Operators\n", - "\n", - "Compare objects using comparison operators. The result is a Boolean value.\n", - "\n", - "| Operator | Description |\n", - "| :---: | :--- |\n", - "| `x == y ` | is `x` equal to `y`? |\n", - "| `x != y` | is `x` not equal to `y`? |\n", - "| `x > y` | is `x` greater than `y`? |\n", - "| `x >= y` | is `x` greater than or equal to `y`? |\n", - "| `x < y` | is `x` less than `y`? |\n", - "| `x <= y` | is `x` less than or equal to `y`? |\n", - "| `x is y` | is `x` the same object as `y`? |" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 56, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2 < 3" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 57, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "\"Data Science\" != \"Deep Learning\"" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2.0 == \"two\"" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "2 == 2.0" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note: we will discuss `is` next week." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Operators on Boolean values.\n", - "\n", - "| Operator | Description |\n", - "| :---: | :--- |\n", - "|`x and y`| are `x` and `y` both true? |\n", - "|`x or y` | is at least one of `x` or `y` true? |\n", - "| `not x` | is `x` false? | " - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "True and True" - ] - }, - { - "cell_type": "code", - "execution_count": 61, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 61, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "True and False" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 62, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "False or False" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 63, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(\"Python 2\" != \"Python 3\") and (2 <= 3)" - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 64, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "not True" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "not not True" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### NoneType\n", - "\n", - "- `NoneType` is its own type in Python.\n", - "- It only has one possible value, `None`\n", - "- You may have seen similar things in other languages, like `null` in Java, etc." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [], - "source": [ - "x = None" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "None\n" - ] - } - ], - "source": [ - "print(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "NoneType" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 149, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 149, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "bool(None)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Dictionaries\n", - "\n", - "Dictionaries are **awesome**! We'll look at those in a lot more detail soon." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Break!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Dictionaries (10 min)\n", - "\n", - "A dictionary is a mapping between key-values pairs." - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], - "source": [ - "house = {'bedrooms': 3, \n", - " 'bathrooms': 2, \n", - " 'city': 'Vancouver', \n", - " 'price': 2499999, \n", - " 'date_sold': (1,3,2015)}\n", - "\n", - "condo = {'bedrooms' : 2, \n", - " 'bathrooms': 1, \n", - " 'city' : 'Burnaby', \n", - " 'price' : 699999, \n", - " 'date_sold': (27,8,2011)\n", - " }" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 3,\n", - " 'bathrooms': 2,\n", - " 'city': 'Vancouver',\n", - " 'price': 2499999,\n", - " 'date_sold': (1, 3, 2015)}" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "house" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can access a specific field of a dictionary with square brackets:" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2499999" - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "house['price']" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Burnaby'" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo['city']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also edit dictionaries (they are mutable):" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'city': 'Burnaby',\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011)}" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo['price'] = 5 # price already in the dict\n", - "condo" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [], - "source": [ - "condo['flooring'] = \"wood\"" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'city': 'Burnaby',\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011),\n", - " 'flooring': 'wood'}" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can delete fields entirely (though I rarely use this):" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [], - "source": [ - "del condo[\"city\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011),\n", - " 'flooring': 'wood'}" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": {}, - "outputs": [], - "source": [ - "condo[5] = 443345" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011),\n", - " 'flooring': 'wood',\n", - " 5: 443345}" - ] - }, - "execution_count": 39, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'bedrooms': 2,\n", - " 'bathrooms': 1,\n", - " 'price': 5,\n", - " 'date_sold': (27, 8, 2011),\n", - " 'flooring': 'wood',\n", - " 5: 443345,\n", - " (1, 2, 3): 777}" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo[(1,2,3)] = 777\n", - "condo" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [ - { - "ename": "KeyError", - "evalue": "'nothere'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/var/folders/64/bfv2dn992m17r4ztvfrt93rh0000gn/T/ipykernel_6265/2495379980.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcondo\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"nothere\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m: 'nothere'" - ] - } - ], - "source": [ - "condo[\"nothere\"]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A sometimes useful trick about default values:" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo[\"bedrooms\"]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "is shorthand for" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo.get(\"bedrooms\")" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "NoneType" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(condo.get('nothere'))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "With this syntax you can also use default values:" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 46, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo.get(\"bedrooms\", \"unknown\")" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'FREEZER'" - ] - }, - "execution_count": 49, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "condo.get(\"fireplaces\", \"FREEZER\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- A common operation is finding the maximum dictionary key by value.\n", - "- There are a few ways to do this, see [this StackOverflow page](https://stackoverflow.com/questions/268272/getting-key-with-maximum-value-in-dictionary).\n", - "- One way of doing it:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "max(word_lengths, key=word_lengths.get)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We saw `word_lengths.get` above - it is saying that we should call this function on each key of the dict to decide how to sort." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Indexing Sequences (Lists and Tuples) (20 min)\n", - "\n", - "- Lists and tuples allow us to store multiple things (\"elements\") in a single object.\n", - "- The elements are _ordered_.\n", - "- We can access values inside a list, tuple, or string using the bracket syntax. \n", - "- Python uses zero-based indexing, which means the first element of the list is in position 0, not position 1." - ] - }, - { - "cell_type": "code", - "execution_count": 87, - "metadata": {}, - "outputs": [], - "source": [ - "my_list = [1, 2, \"THREE\", 4, 0.5]" - ] - }, - { - "cell_type": "code", - "execution_count": 88, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 2, 'THREE', 4, 0.5]\n" - ] - } - ], - "source": [ - "print(my_list)" - ] - }, - { - "cell_type": "code", - "execution_count": 89, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "list" - ] - }, - "execution_count": 89, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(my_list)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can get the length of the list with `len`:" - ] - }, - { - "cell_type": "code", - "execution_count": 90, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 90, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(my_list)" - ] - }, - { - "cell_type": "code", - "execution_count": 91, - "metadata": {}, - "outputs": [], - "source": [ - "today = (1, 2, \"THREE\", 4, 0.5)" - ] - }, - { - "cell_type": "code", - "execution_count": 92, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(1, 2, 'THREE', 4, 0.5)\n" - ] - } - ], - "source": [ - "print(today)" - ] - }, - { - "cell_type": "code", - "execution_count": 93, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "tuple" - ] - }, - "execution_count": 93, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(today)" - ] - }, - { - "cell_type": "code", - "execution_count": 94, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 94, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(today)" - ] - }, - { - "cell_type": "code", - "execution_count": 95, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 'THREE', 4, 0.5]" - ] - }, - "execution_count": 95, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list" - ] - }, - { - "cell_type": "code", - "execution_count": 96, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1" - ] - }, - "execution_count": 96, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 97, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.5" - ] - }, - "execution_count": 97, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[4]" - ] - }, - { - "cell_type": "code", - "execution_count": 98, - "metadata": {}, - "outputs": [ - { - "ename": "IndexError", - "evalue": "list index out of range", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[98], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmy_list\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m]\u001b[49m\n", - "\u001b[0;31mIndexError\u001b[0m: list index out of range" - ] - } - ], - "source": [ - "my_list[5]" - ] - }, - { - "cell_type": "code", - "execution_count": 99, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.5" - ] - }, - "execution_count": 99, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "today[4]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can use negative indices to count backwards from the end of the list." - ] - }, - { - "cell_type": "code", - "execution_count": 101, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 'THREE', 4, 0.5]" - ] - }, - "execution_count": 101, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list" - ] - }, - { - "cell_type": "code", - "execution_count": 102, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.5" - ] - }, - "execution_count": 102, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[-1]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We use the colon `:` to access a subsequence. This is called \"slicing\"." - ] - }, - { - "cell_type": "code", - "execution_count": 103, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[2, 'THREE', 4]" - ] - }, - "execution_count": 103, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[1:4]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Above: note that the start is inclusive and the end is exclusive.\n", - "- So `my_list[1:3]` fetches elements 1 and 2, but not 3.\n", - "- In other words, it gets the 2nd and 3rd elements in the list." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can omit the start or end:" - ] - }, - { - "cell_type": "code", - "execution_count": 104, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 'THREE']" - ] - }, - "execution_count": 104, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[:3]" - ] - }, - { - "cell_type": "code", - "execution_count": 105, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[4, 0.5]" - ] - }, - "execution_count": 105, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[3:]" - ] - }, - { - "cell_type": "code", - "execution_count": 106, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 'THREE', 4, 0.5]" - ] - }, - "execution_count": 106, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "my_list[:] # *almost* same as my_list - more details next week" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Strings behave the same as lists and tuples when it comes to indexing and slicing." - ] - }, - { - "cell_type": "code", - "execution_count": 107, - "metadata": {}, - "outputs": [], - "source": [ - "alphabet = \"abcdefghijklmnopqrstuvwxyz\"" - ] - }, - { - "cell_type": "code", - "execution_count": 108, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'a'" - ] - }, - "execution_count": 108, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 109, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'z'" - ] - }, - "execution_count": 109, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[-1]" - ] - }, - { - "cell_type": "code", - "execution_count": 110, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'x'" - ] - }, - "execution_count": 110, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[-3]" - ] - }, - { - "cell_type": "code", - "execution_count": 111, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'abcde'" - ] - }, - "execution_count": 111, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[:5]" - ] - }, - { - "cell_type": "code", - "execution_count": 112, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'mnopqrst'" - ] - }, - "execution_count": 112, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "alphabet[12:20]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### List Methods\n", - "\n", - "- A list is an object and it has methods for interacting with its data. \n", - "- For example, `list.append(item)` appends an item to the end of the list. \n", - "- See the documentation for more [list methods](https://docs.python.org/3/tutorial/datastructures.html#more-on-lists)." - ] - }, - { - "cell_type": "code", - "execution_count": 113, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[2, 3, 5, 7, 11]" - ] - }, - "execution_count": 113, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "primes = [2,3,5,7,11]\n", - "primes" - ] - }, - { - "cell_type": "code", - "execution_count": 114, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 114, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 115, - "metadata": {}, - "outputs": [], - "source": [ - "primes.append(13)" - ] - }, - { - "cell_type": "code", - "execution_count": 116, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[2, 3, 5, 7, 11, 13]" - ] - }, - "execution_count": 116, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "primes" - ] - }, - { - "cell_type": "code", - "execution_count": 117, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "6" - ] - }, - "execution_count": 117, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 118, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "13" - ] - }, - "execution_count": 118, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "max(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 119, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 119, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "min(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 120, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "41" - ] - }, - "execution_count": 120, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sum(primes)" - ] - }, - { - "cell_type": "code", - "execution_count": 121, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 3, 'Hello', 7]" - ] - }, - "execution_count": 121, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "w =[1,2,3] + [\"Hello\", 7]\n", - "w" - ] - }, - { - "cell_type": "code", - "execution_count": 122, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "list" - ] - }, - "execution_count": 122, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(w)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Mutable vs. Immutable Types\n", - "\n", - "- Strings and tuples are immutable types which means they cannot be modified. \n", - "- Lists are mutable and we can assign new values for its various entries. \n", - "- This is the main difference between lists and tuples." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_list = [\"Indiana\",\"Fang\",\"Linsey\"]\n", - "names_list" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_list[0] = \"Cool guy\"\n", - "names_list" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_tuple = (\"Indiana\",\"Fang\",\"Linsey\")\n", - "names_tuple" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_tuple[0] = \"Not cool guy\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Same goes for strings. Once defined we cannot modifiy the characters of the string." - ] - }, - { - "cell_type": "code", - "execution_count": 127, - "metadata": {}, - "outputs": [], - "source": [ - "my_name = \"Firas\"" - ] - }, - { - "cell_type": "code", - "execution_count": 128, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'str' object does not support item assignment", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[128], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmy_name\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mq\u001b[39m\u001b[38;5;124m'\u001b[39m\n", - "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment" - ] - } - ], - "source": [ - "my_name[-1] = 'q'" - ] - }, - { - "cell_type": "code", - "execution_count": 129, - "metadata": {}, - "outputs": [], - "source": [ - "x = ([1,2,3],5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "x[1] = 7" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "x" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "x[0][1] = 4" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "x" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## String Methods (5 min)\n", - "\n", - "- There are various useful string methods in Python." - ] - }, - { - "cell_type": "code", - "execution_count": 130, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "HOW ARE YOU TODAY?\n" - ] - } - ], - "source": [ - "all_caps = \"HOW ARE YOU TODAY?\"\n", - "print(all_caps)" - ] - }, - { - "cell_type": "code", - "execution_count": 131, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'how are you today?'" - ] - }, - "execution_count": 131, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "new_str = all_caps.lower()\n", - "new_str" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note that the method lower doesn't change the original string but rather returns a new one.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 132, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'HOW ARE YOU TODAY?'" - ] - }, - "execution_count": 132, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "all_caps" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There are *many* string methods. Check out the [documentation](https://docs.python.org/3/library/stdtypes.html#string-methods)." - ] - }, - { - "cell_type": "code", - "execution_count": 133, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['HOW', 'ARE', 'YOU', 'TODAY?']" - ] - }, - "execution_count": 133, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "all_caps.split()" - ] - }, - { - "cell_type": "code", - "execution_count": 134, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 134, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "all_caps.count(\"O\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "One can explicitly cast a string to a list:" - ] - }, - { - "cell_type": "code", - "execution_count": 135, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['H',\n", - " 'O',\n", - " 'W',\n", - " ' ',\n", - " 'A',\n", - " 'R',\n", - " 'E',\n", - " ' ',\n", - " 'Y',\n", - " 'O',\n", - " 'U',\n", - " ' ',\n", - " 'T',\n", - " 'O',\n", - " 'D',\n", - " 'A',\n", - " 'Y',\n", - " '?']" - ] - }, - "execution_count": 135, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "caps_list = list(all_caps)\n", - "caps_list" - ] - }, - { - "cell_type": "code", - "execution_count": 136, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "18" - ] - }, - "execution_count": 136, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(all_caps)" - ] - }, - { - "cell_type": "code", - "execution_count": 137, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "18" - ] - }, - "execution_count": 137, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(caps_list)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### String formatting\n", - "\n", - "- Python has a really awesome way of formatting strings by \"filling in the blanks\" and formatting them nicely. \n", - "- There are a few ways of doing this, but [f-strings](https://realpython.com/python-f-strings/) are what I would recommend." - ] - }, - { - "cell_type": "code", - "execution_count": 138, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hello, my name is Firas. I am 5 years old.\n" - ] - } - ], - "source": [ - "myname = \"Firas\"\n", - "age = 5\n", - "\n", - "new = f\"Hello, my name is {myname}. I am {age} years old.\"\n", - "\n", - "print(new)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Empties" - ] - }, - { - "cell_type": "code", - "execution_count": 139, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 139, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "lst = list() # empty list\n", - "lst" - ] - }, - { - "cell_type": "code", - "execution_count": 140, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 140, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "lst = [] # empty list\n", - "lst" - ] - }, - { - "cell_type": "code", - "execution_count": 141, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "()" - ] - }, - "execution_count": 141, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tup = tuple() # empty tuple\n", - "tup" - ] - }, - { - "cell_type": "code", - "execution_count": 142, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "()" - ] - }, - "execution_count": 142, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tup = () # empty tuple\n", - "tup" - ] - }, - { - "cell_type": "code", - "execution_count": 143, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{}" - ] - }, - "execution_count": 143, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dic = dict() # empty dict\n", - "dic" - ] - }, - { - "cell_type": "code", - "execution_count": 144, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{}" - ] - }, - "execution_count": 144, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dic = {} # empty dict\n", - "dic" - ] - }, - { - "cell_type": "code", - "execution_count": 145, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "set()" - ] - }, - "execution_count": 145, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "st = set() # emtpy set\n", - "st" - ] - }, - { - "cell_type": "code", - "execution_count": 146, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "dict" - ] - }, - "execution_count": 146, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "st = {} # NOT an empty set!\n", - "type(st)" - ] - }, - { - "cell_type": "code", - "execution_count": 147, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "set" - ] - }, - "execution_count": 147, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "st = {1}\n", - "type(st)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Conditionals (10 min)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- [Conditional statements](https://docs.python.org/3/tutorial/controlflow.html) allow us to write programs where only certain blocks of code are executed depending on the state of the program. \n", - "- Let's look at some examples and take note of the keywords, syntax and indentation. \n", - "- Check out the [Python documentation](https://docs.python.org/3/tutorial/controlflow.html) and [Think Python (Chapter 5)](http://greenteapress.com/thinkpython/html/thinkpython006.html) for more information about conditional execution." - ] - }, - { - "cell_type": "code", - "execution_count": 148, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "That's a great name\n" - ] - } - ], - "source": [ - "name = input(\"What's your name?\")\n", - "\n", - "if name.lower() == 'mike':\n", - " print(\"That's my name too!\")\n", - "elif name.lower() == 'santa':\n", - " print(\"That's a funny name.\")\n", - "elif name.lower() == 'firas':\n", - " print(\"That's a great name\")\n", - "else:\n", - " print(f\"Hello {name}! That's a cool name.\")\n", - "\n", - " print('Nice to meet you!')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The main points to notice:\n", - "\n", - "* Use keywords `if`, `elif` and `else`\n", - "* The colon `:` ends each conditional expression\n", - "* Indentation (by 4 empty space) defines code blocks\n", - "* In an `if` statement, the first block whose conditional statement returns `True` is executed and the program exits the `if` block\n", - "* `if` statements don't necessarily need `elif` or `else`\n", - "* `elif` lets us check several conditions\n", - "* `else` lets us evaluate a default block if all other conditions are `False`\n", - "* the end of the entire `if` statement is where the indentation returns to the same level as the first `if` keyword" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If statements can also be **nested** inside of one another:" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "What's your name?Jack\n", - "Hello Jack! That's a cool name.\n", - "Nice to meet you!\n" - ] - } - ], - "source": [ - "name = input(\"What's your name?\")\n", - "\n", - "if name.lower() == 'mike':\n", - " print(\"That's my name too!\")\n", - "elif name.lower() == 'santa':\n", - " print(\"That's a funny name.\")\n", - "else:\n", - " print(\"Hello {0}! That's a cool name.\".format(name))\n", - " if name.lower().startswith(\"super\"):\n", - " print(\"Do you have superpowers?\")\n", - "\n", - "print('Nice to meet you!')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Inline if/else" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [ - "words = [\"the\", \"list\", \"of\", \"words\"]\n", - "\n", - "x = \"long list\" if len(words) > 10 else \"short list\"\n", - "x" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if len(words) > 10:\n", - " x = \"long list\"\n", - "else:\n", - " x = \"short list\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "x" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Preview: Next Class" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Next class we will look at loops, functions, and error handling. After that, we'll be in business for the rest of the course!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "skip" - } - }, - "outputs": [], - "source": [ - "## RISE settings\n", - "\n", - "from IPython.display import IFrame\n", - "\n", - "from traitlets.config.manager import BaseJSONConfigManager\n", - "from pathlib import Path\n", - "\n", - "path = Path.home() / \".jupyter\" / \"nbconfig\"\n", - "cm = BaseJSONConfigManager(config_dir=str(path))\n", - "tmp = cm.update(\n", - " \"rise\",\n", - " {\n", - " \"theme\": \"sky\", # blood is dark, nice\n", - " \"transition\": \"fade\",\n", - " \"start_slideshow_at\": \"selected\",\n", - " \"autolaunch\": False,\n", - " \"width\": \"100%\",\n", - " \"height\": \"100%\",\n", - " \"header\": \"\",\n", - " \"footer\": \"\",\n", - " \"scroll\": True,\n", - " \"enable_chalkboard\": True,\n", - " \"slideNumber\": True,\n", - " \"center\": False,\n", - " \"controlsLayout\": \"edges\",\n", - " \"slideNumber\": True,\n", - " \"hash\": True,\n", - " },\n", - ")" - ] - } - ], - "metadata": { - "celltoolbar": "Slideshow", - "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.10.2" - }, - "vscode": { - "interpreter": { - "hash": "4a3006030bc8f073e17f416a7c98291111bc2dc23e3286a5e86c679c75d3e5ba" - } - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notes/week02/class2B.ipynb b/notes/week02/class2B.ipynb deleted file mode 100644 index 87da827..0000000 --- a/notes/week02/class2B.ipynb +++ /dev/null @@ -1,2477 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - }, - "user_expressions": [] - }, - "source": [ - "# Class 2B: Review of Programming in Python II\n", - "\n", - "We will begin soon!\n", - "\n", - "\n", - "\n", - "
\n", - "
\n", - "
\n", - " Photo by Christina Morillo from Pexels\n", - "
\n", - "\n", - "[Download the (logistics) Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec04PythonReview2.pdf)\n", - "\n", - "
\n", - " Firas Moosvi\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Lecture Outline\n", - "\n", - "- Comments (0 min)\n", - "- Loops\n", - "- Comprehensions\n", - "- Break (5 min)\n", - "- Functions\n", - "- Exceptions\n", - "- Testing\n", - "- Questions and Recap" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Attribution\n", - "\n", - "- The original version of these Python lectures were by [Patrick Walls](https://www.math.ubc.ca/~pwalls/).\n", - "- These lectures were originally delivered by [Mike Gelbart](https://mikegelbart.com) and are [available publicly here](https://www.youtube.com/watch?v=7FLv1ACEl-E&list=PLWmXHcz_53Q26aQzhknaT3zwWvl7w8wQE&index=2)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Comments in python" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [], - "source": [ - "x = 1 # 5 + 5 this is a comment" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], - "source": [ - "# \"\"\"\n", - "# this is a string, which does nothing\n", - "# and can be used as a comment\n", - "# \"\"\"\n", - "\n", - "7\n", - "\n", - "\n", - "x = 1" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Loops" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Loops allow us to execute a block of code multiple times. \n", - "- We will focus on [`for` loops](https://docs.python.org/3/tutorial/controlflow.html#for-statements)" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'I have 6 apples'" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "\"I have 5 apples\"\n", - "\"I have 6 apples\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### `for` loops" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The number is 2 its square is 4\n", - "The number is 7 its square is 49\n", - "hallelujah\n", - "The number is -1 its square is 1\n", - "The number is 5 its square is 25\n", - "hallelujah\n" - ] - } - ], - "source": [ - "for n in [2, 7, -1, 5]:\n", - " print(\"The number is\", n, \"its square is\", n**2)\n", - " if n > 2:\n", - " print(\"hallelujah\")\n", - " # this is inside the loop\n", - "# this is outside the loop" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32,\n", - " 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66,\n", - " 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98])" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import numpy as np\n", - "np.arange(0,100,2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The main points to notice:\n", - "\n", - "* Keyword `for` begins the loop\n", - "* Colon `:` ends the first line of the loop\n", - "* We can iterate over any kind of iterable: list, tuple, range, string. In this case, we are iterating over the values in a list\n", - "* Block of code indented is executed for each value in the list (hence the name \"for\" loops, sometimes also called \"for each\" loops)\n", - "* The loop ends after the variable `n` has taken all the values in the list" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'abcdef'" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "\"abc\" + \"def\"" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Gimme a P!\n", - "Gimme a y!\n", - "Gimme a t!\n", - "Gimme a h!\n", - "Gimme a o!\n", - "Gimme a n!\n", - "\tWhat's that spell?!! Python!\n" - ] - } - ], - "source": [ - "word = \"Python\"\n", - "for letter in word:\n", - " print(\"Gimme a \" + letter + \"!\")\n", - "\n", - "print(\"\\tWhat's that spell?!! \" + word + \"!\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- A very common pattern is to use `for` with `range`. \n", - "- `range` gives you a sequence of integers up to some value." - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n", - "1\n", - "2\n", - "3\n", - "4\n", - "5\n", - "6\n", - "7\n", - "8\n", - "9\n" - ] - } - ], - "source": [ - "for i in range(10):\n", - " print(i)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can also specify a start value and a skip-by value with `range`:" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n", - "11\n", - "21\n", - "31\n", - "41\n", - "51\n", - "61\n", - "71\n", - "81\n", - "91\n" - ] - } - ], - "source": [ - "for i in range(1,101,10):\n", - " print(i)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can write a loop inside another loop to iterate over multiple dimensions of data. Consider the following loop as enumerating the coordinates in a 3 by 3 grid of points." - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(1, 'a')\n", - "(1, 'b')\n", - "(1, 'c')\n", - "(2, 'a')\n", - "(2, 'b')\n", - "(2, 'c')\n", - "(3, 'a')\n", - "(3, 'b')\n", - "(3, 'c')\n" - ] - } - ], - "source": [ - "for x in [1,2,3]:\n", - " for y in [\"a\",\"b\",\"c\"]:\n", - " print((x,y))" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 a\n", - "2 b\n", - "3 c\n", - "4 d\n" - ] - }, - { - "ename": "IndexError", - "evalue": "list index out of range", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[38], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m list_2 \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mc\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124md\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m5\u001b[39m):\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(list_1[i], \u001b[43mlist_2\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m)\n", - "\u001b[0;31mIndexError\u001b[0m: list index out of range" - ] - } - ], - "source": [ - "list_1 = [1,2,3,4,5]\n", - "list_2 = [\"a\",\"b\",\"c\",\"d\"]\n", - "for i in range(5):\n", - " print(list_1[i], list_2[i])" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 a\n", - "2 b\n", - "3 c\n", - "4 d\n" - ] - } - ], - "source": [ - "for i,j in zip(list_1,list_2):\n", - " print(i,j)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can loop through key-value pairs of a dictionary using `.items()`:" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hello\\nWorld\n" - ] - } - ], - "source": [ - "print(\"Hello\\\\nWorld\")" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hello \\n\n", - "World\n" - ] - } - ], - "source": [ - "h = \"\"\"Hello \\\\n\n", - "World\"\"\"\n", - "\n", - "print(h)" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "DSCI 521 is awesome\n", - "DSCI 551 is riveting\n", - "DSCI 511 is naptime!\n" - ] - } - ], - "source": [ - "courses = {521 : \"awesome\",\n", - " 551 : \"riveting\",\n", - " 511 : \"naptime!\"}\n", - "\n", - "for course_num, description in courses.items():\n", - " print(\"DSCI\", course_num, \"is\", description)" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "521 awesome\n", - "551 riveting\n", - "511 naptime!\n" - ] - } - ], - "source": [ - "for course_num,course_desc in courses.items():\n", - " print(course_num, course_desc)\n", - "# print(course_num, courses[course_num])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Above: the general syntax is `for key, value in dictionary.items():`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### `while` loops\n", - "\n", - "- We can also use a [`while` loop](https://docs.python.org/3/reference/compound_stmts.html#while) to excute a block of code several times. \n", - "- In reality, I rarely use these.\n", - "- Beware! If the conditional expression is always `True`, then you've got an infintite loop! \n", - " - (Use the \"Stop\" button in the toolbar above, or Ctrl-C in the terminal, to kill the program if you get an infinite loop.)" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10\n", - "9\n", - "8\n", - "7\n", - "6\n", - "5\n", - "4\n", - "3\n", - "2\n", - "1\n", - "Blast off!\n" - ] - } - ], - "source": [ - "n = 10\n", - "while n > 0:\n", - " print(n)\n", - " n = n - 1\n", - "\n", - "print(\"Blast off!\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Comprehensions\n", - "\n", - "Comprehensions allow us to build lists/sets/dictionaries in one convenient, compact line of code." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### List Comprehensions\n", - "\n", - "List comprehensions are one of my favourite features of Python!" - ] - }, - { - "cell_type": "code", - "execution_count": 50, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]" - ] - }, - "execution_count": 50, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "[hh*10 for hh in range(10)]\n" - ] - }, - { - "cell_type": "code", - "execution_count": 51, - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "['llo', 'bye', 'the', 'ism']" - ] - }, - "execution_count": 51, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "words = [\"hello\", \"goodbye\", \"the\", \"antidisestablishmentarianism\"]\n", - "\n", - "y = [word[-3:] for word in words] # list comprehension\n", - "y" - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "llo\n", - "bye\n", - "the\n", - "ism\n" - ] - } - ], - "source": [ - "for word in words:\n", - " print(word[-3:])" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['llo', 'bye', 'the', 'ism']" - ] - }, - "execution_count": 53, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "y = list()\n", - "for word in words:\n", - " y.append(word[-3:])\n", - "y" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "source": [ - "### Dictionary comprehension" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'hello': 5, 'goodbye': 7, 'the': 3, 'antidisestablishmentarianism': 28}" - ] - }, - "execution_count": 54, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "word_lengths = {word : len(word) for word in words} # dictionary comprehension\n", - "word_lengths" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'hello': 'HELLO',\n", - " 'goodbye': 'GOODBYE',\n", - " 'the': 'THE',\n", - " 'antidisestablishmentarianism': 'ANTIDISESTABLISHMENTARIANISM'}" - ] - }, - "execution_count": 55, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "word_upper = {word : word.upper() for word in words}\n", - "word_upper" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Set Comprehensions" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'o', 'm', 'e'}\n" - ] - } - ], - "source": [ - "y = {word[-1] for word in words} # set comprehension\n", - "print(y)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Tuple Comprehensions" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Tuple comprehensions actually don't exist! But, you can use generators.\n", - "\n", - "See [this StackOverflow post](https://stackoverflow.com/questions/16940293/why-is-there-no-tuple-comprehension-in-python) for (some fun) details!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Break (5 min)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "## Functions\n", - "\n", - "- Define a [**function**](https://docs.python.org/3/tutorial/controlflow.html#defining-functions) to re-use a block of code with different input parameters, also known as **arguments**. \n", - "- For example, define a function called `square` which takes one input parameter `n` and returns the square `n**2`." - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [], - "source": [ - "def square(n):\n", - " n_squared = n**2\n", - " return n_squared\n", - "\n", - "# quick test:\n", - "assert square(2) ==4" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "152399025" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "square(12345)" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "4" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "square(2)" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "10000" - ] - }, - "execution_count": 60, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "square(100)" - ] - }, - { - "cell_type": "code", - "execution_count": 61, - "metadata": {}, - "outputs": [], - "source": [ - "# this will fail \n", - "# square('hello')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Begins with `def` keyword, function name, input parameters and then colon (`:`)\n", - "* Function block defined by indentation\n", - "* Output or \"return\" value of the function is given by the `return` keyword" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Side effects\n", - "\n", - "- If a function changes the variables passed into it, then it is said to have **side effects**\n", - "- Example:" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": {}, - "outputs": [], - "source": [ - "def silly_sum(sri):\n", - " sri.append(0)\n", - " return sum(sri)" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "10" - ] - }, - "execution_count": 63, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "silly_sum([1,2,3,4])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Looks good, like it sums the numbers? But wait...\n" - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "10" - ] - }, - "execution_count": 64, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "lst = [1,2,3,4]\n", - "silly_sum(lst)" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "10" - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "silly_sum(lst)" - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 2, 3, 4, 0, 0]" - ] - }, - "execution_count": 66, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "lst" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- If your function has side effects like this, you must mention it in the documentation (later today).\n", - "- More on how this works next class." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Null return type\n", - "\n", - "If you do not specify a return value, the function returns `None` when it terminates:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def f(x):\n", - " x + 1 # no return!\n", - " if x == 999:\n", - " return\n", - " else:\n", - " return('hello')\n", - "print(f(998))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Designing good functions - DRY principle (15 min)\n", - "\n", - "- DRY: **Don't Repeat Yourself**\n", - "- See [Wikipedia article](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)\n", - "- Consider the task of, for each element of a list, turning it into a palindrome\n", - " - e.g. \"mike\" --> \"mikeekim\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names = [\"milad\", \"rodolfo\", \"tiffany\", \"khalad\", \"jeff\", \"christel\",\"firas\"]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "name = \"mike\"\n", - "name[::-1]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_backwards = list()\n", - "\n", - "names_backwards.append(names[0] + names[0][::-1])\n", - "names_backwards.append(names[1] + names[1][::-1])\n", - "names_backwards.append(names[2] + names[2][::-1])\n", - "names_backwards.append(names[3] + names[3][::-1])\n", - "names_backwards.append(names[4] + names[4][::-1])\n", - "names_backwards.append(names[5] + names[5][::-1])\n", - "names_backwards.append(names[6] + names[6][::-1])\n", - "\n", - "\n", - "names_backwards" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Above: this is gross, terrible, yucky code\n", - " 1. It only works for a list with 3 elements\n", - " 2. It only works for a list named `names`\n", - " 3. If we want to change its functionality, we need to change 3 similar lines of code (Don't Repeat Yourself!!)\n", - " 4. It is hard to understand what it does just by looking at it" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_backwards = list()\n", - "\n", - "for name in names:\n", - " names_backwards.append(name + name[::-1])\n", - " \n", - "names_backwards" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Above: this is slightly better. We have solved problems (1) and (3)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def make_palindromes(names):\n", - " names_backwards = list()\n", - " \n", - " for name in names:\n", - " names_backwards.append(name + name[::-1])\n", - " \n", - " return names_backwards" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p_name = make_palindromes(names)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for p in p_name:\n", - " print(p.upper())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Above: this is even better. We have now also solved problem (2), because you can call the function with any list, not just `names`. \n", - "- For example, what if we had multiple _lists_:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names1 = [\"milad\", \"rodolfo\", \"tiffany\"]\n", - "names2 = [\"Trudeau\", \"Scheer\", \"Singh\", \"Blanchet\", \"May\"]\n", - "names3 = [\"apple\", \"orange\", \"banana\"]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_backwards_1 = list()\n", - "\n", - "for name in names1:\n", - " names_backwards_1.append(name + name[::-1])\n", - " \n", - "names_backwards_1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_backwards_2 = list()\n", - "\n", - "for name in names2:\n", - " names_backwards_2.append(name + name[::-1])\n", - " \n", - "names_backwards_2" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "names_backwards_3 = list()\n", - "\n", - "for name in names3:\n", - " names_backwards_3.append(name + name[::-1])\n", - " \n", - "names_backwards_3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Above: this is very bad also (and imagine if it was 20 lines of code instead of 2). This was problem (2). Our function makes it much better:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "make_palindromes(names1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "make_palindromes(names2)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "make_palindromes(names3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- You could get even more fancy, and put the lists of names into a list (so you have a list of lists). \n", - "- Then you could loop over the list and call the function each time:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for list_of_names in [names1, names2, names3]:\n", - " print(make_palindromes(list_of_names))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Designing good functions" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- How far you go with this is sort of a matter of personal style, and how you choose to apply the DRY principle: DON'T REPEAT YOURSELF!\n", - "- These decisions are often ambiguous. For example: \n", - " - Should `make_palindromes` be a function if I'm only ever doing it once? Twice?\n", - " - Should the loop be inside the function, or outside?\n", - " - Or should there be TWO functions, one that loops over the other??" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- In my personal opinion, `make_palindromes` does a bit too much to be understandable.\n", - "- I prefer this:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def make_palindrome(name):\n", - " return name + name[::-1]\n", - "\n", - "make_palindrome(\"milad\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- From here, we want to \"apply `make_palindrome` to every element of a list\"\n", - "- It turns out this is an extremely common desire, so Python has built-in functions.\n", - "- One of these is `map`, which we'll cover later. But for now, just a comprehension will do:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "[make_palindrome(name) for name in names]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Other function design considerations:\n", - "\n", - "- Should we print output or produce plots inside or outside functions? \n", - " - I would usually say outside, because this is a \"side effect\" of sorts\n", - "- Should the function do one thing or many things?\n", - " - This is a tough one, hard to answer in general" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Optional & keyword arguments\n", - "\n", - "- Sometimes it is convenient to have _default values_ for some arguments in a function. \n", - "- Because they have default values, these arguments are optional, hence \"optional arguments\"\n", - "- Example:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def repeat_string(s, n=2):\n", - " return s*n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "repeat_string(\"mds\", 2)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "repeat_string(\"mds\", 5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Sane defaults:\n", - "\n", - "- Ideally, the default should be carefully chosen. \n", - "- Here, the idea of \"repeating\" something makes me think of having 2 copies, so `n=2` feels like a sane default." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Syntax:\n", - "\n", - "- You can have any number of arguments and any number of optional arguments\n", - "- **All the optional arguments must come after the regular arguments\n", - "- The regular arguments are mapped by the order they appear\n", - "- The optional arguments can be specified out of order" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def example(a, b, c=\"DEFAULT\", d=\"DEFAULT\"):\n", - " print(a,b,c,d)\n", - " \n", - "example(1,2,3,4)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Using the defaults for `c` and `d`:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(1,2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying `c` and `d` as **keyword arguments** (i.e. by name):" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(1,2,c=3,d=4)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying only one of the optional arguments, by keyword:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(1,2,c=3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Or the other:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(1,2,d=4)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying all the arguments as keyword arguments, even though only `c` and `d` are optional:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(a=1,b=2,c=3,d=4)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying `c` by the fact that it comes 3rd (I do not recommend this because I find it is confusing):" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(1,2,3) " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying the optional arguments by keyword, but in the wrong order (this is also somewhat confusing, but not so terrible - I am OK with it):" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(1,2,d=4,c=3) " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying the non-optional arguments by keyword (I am fine with this):" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(a=1,b=2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying the non-optional arguments by keyword, but in the wrong order (not recommended, I find it confusing):" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(b=2,a=1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying keyword arguments before non-keyword arguments (this throws an error):" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "example(a=2,b=1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- In general, I am used to calling non-optional arguments by order, and optional arguments by keyword.\n", - "- The language allows us to deviate from this, but it can be unnecessarily confusing sometimes." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### `kwargs`:\n", - "\n", - "- You can also call/define functions with `*args` and `**kwargs`; see, e.g. [here](https://realpython.com/python-kwargs-and-args/)\n", - "- Do not instantiate objects in the function definition - see [here](https://docs.python-guide.org/writing/gotchas/) under \"Mutable Default Arguments\"" - ] - }, - { - "cell_type": "code", - "execution_count": 67, - "metadata": {}, - "outputs": [], - "source": [ - "def example(a, b=[]): # don't do this!\n", - " return 0" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": {}, - "outputs": [], - "source": [ - "def example(a, b=None): # insted, do this\n", - " if b is None:\n", - " b = []\n", - " return 0" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Anonymous functions (5 min)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There are two ways to define functions in Python:" - ] - }, - { - "cell_type": "code", - "execution_count": 69, - "metadata": {}, - "outputs": [], - "source": [ - "def add_one(x):\n", - " return x+1" - ] - }, - { - "cell_type": "code", - "execution_count": 70, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "8.2" - ] - }, - "execution_count": 70, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "add_one(7.2)" - ] - }, - { - "cell_type": "code", - "execution_count": 71, - "metadata": {}, - "outputs": [], - "source": [ - "add_one = lambda x: x+1 " - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "function" - ] - }, - "execution_count": 72, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(add_one)" - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "8.2" - ] - }, - "execution_count": 73, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "add_one(7.2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The two approaches above are identical. The one with `lambda` is called an **anonymous function**.\n", - "\n", - "Some differences:\n", - "\n", - "- anonymous functions can only take up one line of code, so they aren't appropriate in most cases.\n", - "- anonymous functions evaluate to a function (remember, functions are first-class objects) immediate, so we can do weird stuff with them." - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "13" - ] - }, - "execution_count": 74, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(lambda x,y: x+y)(6,7)" - ] - }, - { - "cell_type": "code", - "execution_count": 75, - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'evaluate_function_on_x_plus_1' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[75], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mevaluate_function_on_x_plus_1\u001b[49m(\u001b[38;5;28;01mlambda\u001b[39;00m x: x\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m5\u001b[39m)\n", - "\u001b[0;31mNameError\u001b[0m: name 'evaluate_function_on_x_plus_1' is not defined" - ] - } - ], - "source": [ - "evaluate_function_on_x_plus_1(lambda x: x**2, 5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Above:\n", - "\n", - "- First, `lambda x: x**2` evaluates to a value of type `function`\n", - " - Notice that this function is never given a name - hence \"anonymous functions\" !\n", - "- Then, the function and the integer `5` are passed into `evaluate_function_on_x_plus_1`\n", - "- At which point the anonymous function is evaluated on `5+1`, and we get `36`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Exceptions, `try`/`except` (10 min)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- If something goes wrong, we don't want the code to crash - we want it to **fail gracefully**.\n", - "- In Python, this can be accomplished using `try`/`except`:\n", - "- Here is a basic example:" - ] - }, - { - "cell_type": "code", - "execution_count": 76, - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'this_variable_does_not_exist' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[76], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mthis_variable_does_not_exist\u001b[49m\n", - "\u001b[0;31mNameError\u001b[0m: name 'this_variable_does_not_exist' is not defined" - ] - } - ], - "source": [ - "this_variable_does_not_exist" - ] - }, - { - "cell_type": "code", - "execution_count": 77, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "You did something bad!\n" - ] - } - ], - "source": [ - "try:\n", - " this_variable_does_not_exist\n", - "except:\n", - "# pass\n", - " print(\"You did something bad!\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Python tries to execute the code in the `try` block.\n", - "- If an error is encountered, we \"catch\" this in the `except` block (also called `try`/`catch` in other languages).\n", - "- There are many different error types, or **exceptions** - we saw `NameError` above. " - ] - }, - { - "cell_type": "code", - "execution_count": 78, - "metadata": {}, - "outputs": [ - { - "ename": "ZeroDivisionError", - "evalue": "division by zero", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[78], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;241;43m5\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\n", - "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" - ] - } - ], - "source": [ - "5/0" - ] - }, - { - "cell_type": "code", - "execution_count": 79, - "metadata": {}, - "outputs": [ - { - "ename": "IndexError", - "evalue": "list index out of range", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[79], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m my_list \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m]\n\u001b[0;32m----> 2\u001b[0m \u001b[43mmy_list\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m]\u001b[49m\n", - "\u001b[0;31mIndexError\u001b[0m: list index out of range" - ] - } - ], - "source": [ - "my_list = [1,2,3]\n", - "my_list[5]" - ] - }, - { - "cell_type": "code", - "execution_count": 80, - "metadata": {}, - "outputs": [ - { - "ename": "IndexError", - "evalue": "list index out of range", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[80], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# (note: this is also valid syntax, just very confusing)\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m]\u001b[49m\n", - "\u001b[0;31mIndexError\u001b[0m: list index out of range" - ] - } - ], - "source": [ - "# (note: this is also valid syntax, just very confusing)\n", - "[1,2,3][5]" - ] - }, - { - "cell_type": "code", - "execution_count": 81, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'tuple' object does not support item assignment", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[81], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m my_tuple \u001b[38;5;241m=\u001b[39m (\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m \u001b[43mmy_tuple\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n", - "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" - ] - } - ], - "source": [ - "my_tuple = (1,2,3)\n", - "my_tuple[0] = 0" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Ok, so there are apparently a bunch of different errors one could run into. \n", - "- With `try`/`except` you can also catch the exception itself:" - ] - }, - { - "cell_type": "code", - "execution_count": 82, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "You did something bad!\n", - "name 'this_variable_does_not_exist' is not defined\n", - "\n" - ] - } - ], - "source": [ - "try:\n", - " this_variable_does_not_exist\n", - "except Exception as ex:\n", - " print(\"You did something bad!\")\n", - " print(ex)\n", - " print(type(ex))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- In the above, we caught the exception and assigned it to the variable `ex` so that we could print it out.\n", - "- This is useful because you can see what the error message would have been, without crashing your program." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- You can also catch specific exceptions types, like so:" - ] - }, - { - "cell_type": "code", - "execution_count": 83, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "You made a name error!\n" - ] - } - ], - "source": [ - "try:\n", - " this_variable_does_not_exist\n", - "except TypeError:\n", - " print(\"You made a type error!\")\n", - "except NameError:\n", - " print(\"You made a name error!\")\n", - "except:\n", - " print(\"You made some other sort of error\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- The final `except` would trigger if the error is none of the above types, so this sort of has an `if`/`elif`/`else` feel to it. \n", - "- There are some extra features, in particular an `else` and `finally` block; if you are interested, see e.g., [here](https://www.w3schools.com/python/python_try_except.asp)." - ] - }, - { - "cell_type": "code", - "execution_count": 84, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "You made some other sort of error\n" - ] - } - ], - "source": [ - "try:\n", - " 5/0\n", - "except TypeError:\n", - " print(\"You made a type error!\")\n", - "except NameError:\n", - " print(\"You made a name error!\")\n", - "except Exception as ex:\n", - " print(\"You made some other sort of error\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Ideally, try to make your `try`/`except` blocks specific, and try not to put more errors inside the `except`... " - ] - }, - { - "cell_type": "code", - "execution_count": 85, - "metadata": {}, - "outputs": [ - { - "ename": "ZeroDivisionError", - "evalue": "division by zero", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[85], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m----> 2\u001b[0m \u001b[43mthis_variable_does_not_exist\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m:\n", - "\u001b[0;31mNameError\u001b[0m: name 'this_variable_does_not_exist' is not defined", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[85], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m this_variable_does_not_exist\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m:\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;241;43m5\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\n", - "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" - ] - } - ], - "source": [ - "try:\n", - " this_variable_does_not_exist\n", - "except:\n", - " 5/0" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- This is a bit much, but it does happen sometimes :(" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Using `raise`\n", - "\n", - "- You can also write code that raises an exception on purpose, using `raise`" - ] - }, - { - "cell_type": "code", - "execution_count": 86, - "metadata": {}, - "outputs": [], - "source": [ - "def add_one(x):\n", - " return x+1" - ] - }, - { - "cell_type": "code", - "execution_count": 87, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "can only concatenate str (not \"int\") to str", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[87], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43madd_one\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mblah\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", - "Cell \u001b[0;32mIn[86], line 2\u001b[0m, in \u001b[0;36madd_one\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21madd_one\u001b[39m(x):\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mx\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\n", - "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" - ] - } - ], - "source": [ - "add_one(\"blah\")" - ] - }, - { - "cell_type": "code", - "execution_count": 88, - "metadata": {}, - "outputs": [], - "source": [ - "def add_one(x):\n", - " if not isinstance(x, float) and not isinstance(x, int):\n", - " raise Exception(\"Sorry, x must be numeric\")\n", - " \n", - " return x+1" - ] - }, - { - "cell_type": "code", - "execution_count": 89, - "metadata": {}, - "outputs": [ - { - "ename": "Exception", - "evalue": "Sorry, x must be numeric", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[89], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43madd_one\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mblah\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n", - "Cell \u001b[0;32mIn[88], line 3\u001b[0m, in \u001b[0;36madd_one\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21madd_one\u001b[39m(x):\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mfloat\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mint\u001b[39m):\n\u001b[0;32m----> 3\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSorry, x must be numeric\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m x\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m\n", - "\u001b[0;31mException\u001b[0m: Sorry, x must be numeric" - ] - } - ], - "source": [ - "add_one(\"blah\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- This is useful when your function is complicated and would fail in a complicated way, with a weird error message.\n", - "- You can make the cause of the error much clearer to the _caller_ of the function.\n", - "- Thus, your function is more usable this way.\n", - "- If you do this, you should ideally describe these exceptions in the function documentation, so a user knows what to expect if they call your function. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- You can also raise other types of exceptions, or even define your own exception types, as in lab 2.\n", - "- You can also use `raise` by itself to raise whatever exception was going on:" - ] - }, - { - "cell_type": "code", - "execution_count": 90, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "You did something bad!\n" - ] - }, - { - "ename": "NameError", - "evalue": "name 'this_variable_does_not_exist' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[90], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m----> 2\u001b[0m \u001b[43mthis_variable_does_not_exist\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m:\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mYou did something bad!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", - "\u001b[0;31mNameError\u001b[0m: name 'this_variable_does_not_exist' is not defined" - ] - } - ], - "source": [ - "try:\n", - " this_variable_does_not_exist\n", - "except:\n", - " print(\"You did something bad!\")\n", - " raise" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- Here, the original exception is raised after we ran some other code." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Testing" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### `assert` statements\n", - "\n", - "- `assert` statementS cause your program to fail if the condition is `False`.\n", - "- They can be used as sanity checks for your program.\n", - "- There are more sophisticated way to \"test\" your programs, which we'll discuss in Workflows.\n", - "- The syntax is:\n", - "\n", - "```python\n", - "assert expression , \"Error message if expression is False or raises an error.\"\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": 91, - "metadata": {}, - "outputs": [ - { - "ename": "AssertionError", - "evalue": "4 is not equal to 5.", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[91], line 5\u001b[0m\n\u001b[1;32m 2\u001b[0m b \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m5\u001b[39m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# Change this assert statement so a and b is used instead of \"hard-coded 1 and 2\"\u001b[39;00m\n\u001b[0;32m----> 5\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m a \u001b[38;5;241m==\u001b[39m b , \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00ma\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is not equal to \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mb\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", - "\u001b[0;31mAssertionError\u001b[0m: 4 is not equal to 5." - ] - } - ], - "source": [ - "a = 4\n", - "b = 5\n", - "\n", - "# Change this assert statement so a and b is used instead of \"hard-coded 1 and 2\"\n", - "assert a == b , f\"{a} is not equal to {b}.\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Systematic Program Design" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A systematic approach to program design is a general set of steps to follow when writing programs. Our approach includes:\n", - "\n", - "1. Write a stub: a function that does nothing but accept all input parameters and return the correct datatype.\n", - "2. Write tests to satisfy the design specifications.\n", - "3. Outline the program with pseudo-code.\n", - "4. Write code and test frequently.\n", - "5. Write documentation.\n", - "\n", - "The key point: write tests BEFORE you write code.\n", - "\n", - "- You do not have to do this in MDS, but you may find it surprisingly helpful.\n", - "- Often writing tests helps you think through what you are trying to accomplish.\n", - "- It's best to have that clear before you write the actual code." - ] - }, - { - "cell_type": "code", - "execution_count": 105, - "metadata": {}, - "outputs": [], - "source": [ - "# Task: Let's calculate area of a rectangle, given length and width" - ] - }, - { - "cell_type": "code", - "execution_count": 106, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "the area should be : 25 and is 25\n", - "the area should be : 25 and is 25\n" - ] - }, - { - "data": { - "text/plain": [ - "25" - ] - }, - "execution_count": 106, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def calculate_rectangle_area(length, width):\n", - " \"\"\" Computes the area of a rectangle given a length and a width\n", - " inputs: length (float) and width(float)\n", - " \n", - " oututs: area (float)\n", - " \"\"\"\n", - " \n", - " # Check the inputs\n", - " # check if length and width are floats\n", - " \n", - " # Compute area\n", - " area = length * width\n", - " \n", - " print(f\"the area should be : {length * width} and is {area}\")\n", - " \n", - " return area\n", - "\n", - "assert calculate_rectangle_area(5,5) == 25, \"the function is not quite correct because the area of a 5x5 should be 25.\"\n", - "calculate_rectangle_area(5,5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Testing woes - false positives\n", - "\n", - "- **Just because all your tests pass, this does not mean your program is correct!!**\n", - "- This happens all the time. How to deal with it?\n", - " - Write a lot of tests!\n", - " - Don't be overconfident, even after writing a lot of tests!" - ] - }, - { - "cell_type": "code", - "execution_count": 101, - "metadata": {}, - "outputs": [], - "source": [ - "def sample_median(x):\n", - " \"\"\"Finds the median of a list of numbers.\"\"\"\n", - " x_sorted = sorted(x)\n", - " return x_sorted[len(x_sorted)//2]\n", - "\n", - "assert sample_median([1,2,3,4,5]) == 3\n", - "assert sample_median([0,0,0,0]) == 0" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Looks good? ... ?\n", - "\n", - "




" - ] - }, - { - "cell_type": "code", - "execution_count": 102, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 102, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "4//2 \n", - "\n", - "#is equivalent to\n", - "\n", - "int(4/2)" - ] - }, - { - "cell_type": "code", - "execution_count": 103, - "metadata": {}, - "outputs": [ - { - "ename": "AssertionError", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[103], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m sample_median([\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m,\u001b[38;5;241m4\u001b[39m]) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m2.5\u001b[39m\n", - "\u001b[0;31mAssertionError\u001b[0m: " - ] - } - ], - "source": [ - "assert sample_median([1,2,3,4]) == 2.5" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "




" - ] - }, - { - "cell_type": "code", - "execution_count": 100, - "metadata": {}, - "outputs": [], - "source": [ - "assert sample_median([1,3,2]) == 2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Testing woes - false negatives\n", - "\n", - "- It can also happen, though more rarely, that your tests fail but your program is correct.\n", - "- This means there is something wrong with your test.\n", - "- For example, in the autograding for lab1 this happened to some people, because of tiny roundoff errors." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Corner cases\n", - "\n", - "- A **corner case** is an input that is reasonable but a bit unusual, and may trip up your code.\n", - "- For example, taking the median of an empty list, or a list with only one element. \n", - "- Often it is desirable to add test cases to address corner cases." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "assert sample_median([1]) == 1" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- In this case the code worked with no extra effort, but sometimes we need `if` statements to handle the weird cases.\n", - "- Sometimes we **want** the code to throw an error (e.g. median of an empty list)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Questions and Recap?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "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.10.2" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notes/week02/classA.md b/notes/week02/classA.md deleted file mode 100644 index db82601..0000000 --- a/notes/week02/classA.md +++ /dev/null @@ -1,7 +0,0 @@ -# Class Meeting 1 - -## Slides from Lecture - -Will be available here after the lecture. - - \ No newline at end of file diff --git a/notes/week02/homework.md b/notes/week02/homework.md deleted file mode 100644 index 70bc2b8..0000000 --- a/notes/week02/homework.md +++ /dev/null @@ -1,10 +0,0 @@ -# Homework - -````{card} -This week the homework assignment is on Chapter 2, and is posted on Mastering physics. - -```{button-link} https://portal.mypearson.com -Mastering Physics - -``` -```` \ No newline at end of file diff --git a/notes/week02/images/JB.key b/notes/week02/images/JB.key deleted file mode 100644 index 2899188..0000000 Binary files a/notes/week02/images/JB.key and /dev/null differ diff --git a/notes/week02/images/base.png b/notes/week02/images/base.png deleted file mode 100644 index 7e0a927..0000000 Binary files a/notes/week02/images/base.png and /dev/null differ diff --git a/notes/week02/images/bus_stop.jpg b/notes/week02/images/bus_stop.jpg deleted file mode 100644 index 707f70c..0000000 Binary files a/notes/week02/images/bus_stop.jpg and /dev/null differ diff --git a/notes/week02/images/notebook1.png b/notes/week02/images/notebook1.png deleted file mode 100644 index 73b2896..0000000 Binary files a/notes/week02/images/notebook1.png and /dev/null differ diff --git a/notes/week02/images/notebook2.png b/notes/week02/images/notebook2.png deleted file mode 100644 index 78b537e..0000000 Binary files a/notes/week02/images/notebook2.png and /dev/null differ diff --git a/notes/week02/images/notebook3.png b/notes/week02/images/notebook3.png deleted file mode 100644 index 01b9af4..0000000 Binary files a/notes/week02/images/notebook3.png and /dev/null differ diff --git a/notes/week02/images/notebook4.png b/notes/week02/images/notebook4.png deleted file mode 100644 index 44df671..0000000 Binary files a/notes/week02/images/notebook4.png and /dev/null differ diff --git a/notes/week02/images/notebook5.png b/notes/week02/images/notebook5.png deleted file mode 100644 index 887b385..0000000 Binary files a/notes/week02/images/notebook5.png and /dev/null differ diff --git a/notes/week02/images/notebook6.png b/notes/week02/images/notebook6.png deleted file mode 100644 index 716fb47..0000000 Binary files a/notes/week02/images/notebook6.png and /dev/null differ diff --git a/notes/week02/images/notebook7.png b/notes/week02/images/notebook7.png deleted file mode 100644 index 12667e0..0000000 Binary files a/notes/week02/images/notebook7.png and /dev/null differ diff --git a/notes/week02/images/programming.jpg b/notes/week02/images/programming.jpg deleted file mode 100644 index ba8254e..0000000 Binary files a/notes/week02/images/programming.jpg and /dev/null differ diff --git a/notes/week02/lab.md b/notes/week02/lab.md deleted file mode 100644 index 75a2dce..0000000 --- a/notes/week02/lab.md +++ /dev/null @@ -1,13 +0,0 @@ -# Lab - - -````{card} - -The lab information for this week is in the Physics 111 Lab canvas course... - -```{button-link} https://canvas.ubc.ca/courses/66799 -Physics 111 Lab Canvas -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/week02/learninglogs.md b/notes/week02/learninglogs.md deleted file mode 100644 index b6e624e..0000000 --- a/notes/week02/learninglogs.md +++ /dev/null @@ -1,16 +0,0 @@ -# Learning Logs - -This week's learning log assignment is now posted on Canvas: - -https://canvas.ubc.ca/courses/63995/quizzes/255367 - -````{card} - -This week's learning log assignment is now posted on Canvas. - -```{button-link} https://canvas.ubc.ca/courses/63995/quizzes/255367 -Learning Log #1 -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` diff --git a/notes/week02/readings.md b/notes/week02/readings.md deleted file mode 100644 index dfb3b0d..0000000 --- a/notes/week02/readings.md +++ /dev/null @@ -1,35 +0,0 @@ -# Readings - -This week the readings assignments are listed below: - - - - - -````{card} - -If you have access to the eText, click here to access the eText. - -```{button-link} https://portal.mypearson.com -Pearson eText -:type: url -:classes: btn-outline-warning btn-block stretched-link text-dark -``` -```` - -```{dropdown} -:open: -
- -
-``` \ No newline at end of file diff --git a/notes/week02/rise.css b/notes/week02/rise.css deleted file mode 100644 index c3a7dfb..0000000 --- a/notes/week02/rise.css +++ /dev/null @@ -1,80 +0,0 @@ -/* ---------- markdown cells - */ -body.rise-enabled div.inner_cell>div.text_cell_render.rendered_html { - font-size: 120%; -} - - -/* ---------- code blocks inside markdown - i.e. within ``` lines, or 4-space indented - */ -div.inner_cell>div.text_cell_render.rendered_html>pre { - margin: 0px; -} - -/* ----------- code to remove space above markdown headers - */ -div.inner_cell>div.text_cell_render.rendered_html h1 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h2 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h3 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h4 { - margin-top: 0px; -} - -div.inner_cell>div.text_cell_render.rendered_html>pre>code { - font-size: 70%; -} - -/* ---------- tables (from SO) - */ -.rendered_html table, .rendered_html th, .rendered_html tr, .rendered_html td { - font-size: 120%; -} - -/* ---------- Left part of code cells - from this SO answer: https://stackoverflow.com/a/47263575; - /* Narrow the prompts */ -div.prompt_container { - min-width: 5ex; -} -/* Hide prompts altogether for non-code cells */ -.cell:not(.code_cell) .prompt { - display: none; -} -/* ---------- Width of cells - */ -.container { - width:95% !important; -} - - -/* ---------- Vertical Whitespace - */ -.vspace { - margin-top:50px; -} -/* -div.cell.code_cell.rendered.selected, { - border-width:10px; - border-style:solid; - border-color:red; -} */ - - -/* Removes the border of cells */ - -div.cell { - border-width:0px; -} - -/* Increases the thickness of the blue and green (whether or not the cell is selected */ - -div.cell.selected:before; .edit_mode div.cell.selected:before { - width: 20px; -} diff --git a/notes/week02/test.md b/notes/week02/test.md deleted file mode 100644 index 61b96cb..0000000 --- a/notes/week02/test.md +++ /dev/null @@ -1,13 +0,0 @@ -# Test 0 - -````{card} - -This week is your first test - it is NOT for marks, but is not optional. -It will cover the course policies and will be timed to give you practice on how the testing system works. -This test will be open to you after the Week 2 lecture. - -```{button-link} https://canvas.ubc.ca/courses/63995/quizzes/256495 -Test0 is available - -``` -```` \ No newline at end of file diff --git a/notes/week02/videos.md b/notes/week02/videos.md deleted file mode 100644 index be8100e..0000000 --- a/notes/week02/videos.md +++ /dev/null @@ -1,55 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - - - -``` -```` - -## Required Videos - -There are no required videos this week! - -## Optional Videos - -```{dropdown} 1. Converting Decimal to Binary - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 2. Converting Binary to Decimal - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 3. More on Time Complexity - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` \ No newline at end of file diff --git a/notes/week02/week02_summary.md b/notes/week02/week02_summary.md deleted file mode 100755 index f92f85b..0000000 --- a/notes/week02/week02_summary.md +++ /dev/null @@ -1,6 +0,0 @@ -(page_topic2)= -Week 2 -======================= - -This week we will be doing a Python Introduction so that we're all on the same page before we start getting to some programming and design. -In terms of content, we'll learn about Python dataypes, conditionals, loops, functions, and error handling. \ No newline at end of file diff --git a/notes/week03/class3A.md b/notes/week03/class3A.md deleted file mode 100644 index 22a9dc6..0000000 --- a/notes/week03/class3A.md +++ /dev/null @@ -1,23 +0,0 @@ -# Class Meeting 3A - -Below are the slides from today's class embedded. -Feel free to download them to keep them locally, or leave them archived here and just bookmark them. -We will leave the website open even after the course is over for a reasonable number of years. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec05efficiency.pdf) - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week03/class3B.md b/notes/week03/class3B.md deleted file mode 100644 index 4a43481..0000000 --- a/notes/week03/class3B.md +++ /dev/null @@ -1,23 +0,0 @@ -# Class Meeting 3B - -Below are the slides from today's class embedded. -Feel free to download them to keep them locally, or leave them archived here and just bookmark them. -We will leave the website open even after the course is over for a reasonable number of years. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec06knitting1.pdf) - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week03/homework.md b/notes/week03/homework.md deleted file mode 100644 index 3f48661..0000000 --- a/notes/week03/homework.md +++ /dev/null @@ -1,11 +0,0 @@ -# Homework - -````{card} - -This week the homework assignment is on Chapter 3, and is posted on Mastering physics. - -```{button-link} https://portal.mypearson.com -Mastering Physics - -``` -```` \ No newline at end of file diff --git a/notes/week03/lab.md b/notes/week03/lab.md deleted file mode 100644 index 75a2dce..0000000 --- a/notes/week03/lab.md +++ /dev/null @@ -1,13 +0,0 @@ -# Lab - - -````{card} - -The lab information for this week is in the Physics 111 Lab canvas course... - -```{button-link} https://canvas.ubc.ca/courses/66799 -Physics 111 Lab Canvas -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/week03/learninglogs.md b/notes/week03/learninglogs.md deleted file mode 100644 index 623e811..0000000 --- a/notes/week03/learninglogs.md +++ /dev/null @@ -1,66 +0,0 @@ -# Learning Logs - -This week's learning log assignment will be posted on Canvas by Thursday. - -Here are the questions you will be asked to answer in the learning logs. - -## Task 1: Test Reflection - -This week you will have your first real test in Physics 111 ! -I want you to complete this reflection **after** you finish your test so you can reflect on your experience properly. -You will not receive your test grade until after the learning log is due - this is intentional. - -Q1.1 - How did you prepare for the test (your answers are not graded, so there is no need to lie or exaggerate!) ? Answer in one or two sentences. - -Q1.2 - Do you feel that your preparation helped you on the test this week? Answer in one or two sentences. - -Q1.3 - Will you do anything differently (preparation-wise) for the next tests? Answer in one or two sentences. - -Q1.4 - Select a question from the test that you know you got wrong and do ONE of three things: - -A) explain the misconception that you had that caused you to get the question wrong. - -B) solve the question (or one like it) that you got wrong - the exact numbers or the details of the question do not matter, a similar conceptual question is sufficient. You can attach a picture, or write it in text. - -C) You can skip this question if you do not feel like you got a question wrong. - -Q1.5 - Do you plan to take the Bonus-Test next week to improve your mark? Answer in one or two sentences. - -Q1.6 - Is there anything else you want me to know about your test ? Answer in one or two sentences. - -Q1.7 - What score do you think you got on this test? - -## Task 2: Renew your vows - -Each week, I am asking you to type out the integrity pledge, letter by letter, so you understand how important it is to me that you maintain your academic integrity as you go through this course. - - - -## Task 3: Well-being check - -One of my goals this year is to help you (as best I can) manage your stress and anxieties by "measuring it" on a weekly basis and intervening or making suggestions during our weekly class meeting. -This is an exciting time for all of you as many of you are starting your undergraduate studies. -With this new excitement, you may be feeling additional stress and anxiety as you learn to manage this new life with its drastic changes, that too in the middle of a pandemic. -In terms of providing support for you as an instructor I’d like for us to measure/rate your anxiety and stress levels - I understand that you may not know what level of stress and/or anxiety is appropriate at this level of your education so feel free to note that! - -Q1: On a scale of 1-10, rate your CURRENT level of anxiety and stress: - -Anxiety: 1-10 -Stress: 1-10 - -Q2: On a scale of 1-10, rate WHERE DO YOU THINK YOUR level of anxiety and stress SHOULD BE: - -Anxiety: 1-10 -Stress: 1-10 - -Q3: Is there anything else you would like to tell me? - -[Open Text] - -I’ll do what I can within my role as an instructor, in terms of workload and due dates. -Part of undergraduate life and healthy living is finding ways to manage your stress and anxiety in a manner that is effective for you - this will look different for each person! -If you want to explore additional resources, start with the ones listed at [UBCV Health and wellbeing](https://students.ubc.ca/health) and see if the tips there work for you! - -Finally, remember (from the course syllabus): as I'm sure you're aware, *there is a global pandemic* happening right now and we could all use some extra compassion and humanity. -If you're going through something that is affecting you (course or otherwise), you are always welcome to come and talk to me about it. -If I am not able to help you myself, then I can probably direct you to the right person or resource. diff --git a/notes/week03/lecture.md b/notes/week03/lecture.md deleted file mode 100644 index ac35a3f..0000000 --- a/notes/week03/lecture.md +++ /dev/null @@ -1,15 +0,0 @@ -# Lecture - -This week we will do go over some key clicker questions from Chapter 2 and 3 in preparation for the test later today. - -## Sli.do Polls - -You can go to [https://sli.do/physics111](https://app.sli.do/event/lk89xpvr/live/polls) in a new tab or use the embedded poll here: - - - -## Slides from Lecture - -Will be available here after the lecture. - - \ No newline at end of file diff --git a/notes/week03/readings.md b/notes/week03/readings.md deleted file mode 100644 index 019ec25..0000000 --- a/notes/week03/readings.md +++ /dev/null @@ -1,16 +0,0 @@ -# Readings - -This week the readings assignments are: - - - -````{card} - -If you have access to the eText, click here to access the eText. - -```{button-link} https://portal.mypearson.com -Pearson eText -:type: url -:classes: btn-outline-warning btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/week03/test.md b/notes/week03/test.md deleted file mode 100644 index 73e1301..0000000 --- a/notes/week03/test.md +++ /dev/null @@ -1,13 +0,0 @@ -# Test 1 - -````{card} - -This week you will have your first Test, and it will mostly be on the contents of Chapter 2 and 3. -Remember that Test 1 will be available starting at Thursday at 6:00 PM PDT and will remain available until Saturday at 6:00 PM. -You will have 60 minutes to complete the test. - -```{button-link} https://canvas.ubc.ca/courses/63995/assignments -Test 1 on Canvas - -``` -```` \ No newline at end of file diff --git a/notes/week03/videos.md b/notes/week03/videos.md deleted file mode 100644 index e47f457..0000000 --- a/notes/week03/videos.md +++ /dev/null @@ -1,80 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - - - - - - -``` -```` - -## Required Videos - -Below are the assigned videos for this week. - -### Videos before Tuesday's class - -```{dropdown} 1. Handcraft - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 2. Quantifying the Task - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 3. Colour Representation - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -### Videos before Thursday's class - -```{dropdown} 4. Handcraft Program Design - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 5. Classes in Python - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` \ No newline at end of file diff --git a/notes/week03/week03_summary.md b/notes/week03/week03_summary.md deleted file mode 100755 index 0a20a5c..0000000 --- a/notes/week03/week03_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic3)= -Week 3 -======================= - -This week we be learning about Python classes, knitting, the `dataclass`, and other fun things! \ No newline at end of file diff --git a/notes/week04/class4A.md b/notes/week04/class4A.md deleted file mode 100644 index 22d1457..0000000 --- a/notes/week04/class4A.md +++ /dev/null @@ -1,23 +0,0 @@ -# Class Meeting 4A - -Below are the slides from today's class embedded. -Feel free to download them to keep them locally, or leave them archived here and just bookmark them. -We will leave the website open even after the course is over for a reasonable number of years. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec07knitting2.pdf) - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week04/class4B.md b/notes/week04/class4B.md deleted file mode 100644 index 699bfaa..0000000 --- a/notes/week04/class4B.md +++ /dev/null @@ -1,23 +0,0 @@ -# Class Meeting 4B - -We're going to change things up for today and switch today's class to a Review and catch-up class with no new content. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec08_Review.pdf) - -## Optional links for today - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week04/homework.md b/notes/week04/homework.md deleted file mode 100644 index fbefa6a..0000000 --- a/notes/week04/homework.md +++ /dev/null @@ -1,11 +0,0 @@ -# Homework - -````{card} - -This week the homework assignment is on Chapter 2, and is posted on Mastering physics. - -```{button-link} https://portal.mypearson.com -Mastering Physics - -``` -```` \ No newline at end of file diff --git a/notes/week04/lab.md b/notes/week04/lab.md deleted file mode 100644 index 75a2dce..0000000 --- a/notes/week04/lab.md +++ /dev/null @@ -1,13 +0,0 @@ -# Lab - - -````{card} - -The lab information for this week is in the Physics 111 Lab canvas course... - -```{button-link} https://canvas.ubc.ca/courses/66799 -Physics 111 Lab Canvas -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/week04/learninglogs.md b/notes/week04/learninglogs.md deleted file mode 100644 index 3e53e9b..0000000 --- a/notes/week04/learninglogs.md +++ /dev/null @@ -1,52 +0,0 @@ -# Learning Logs - -This week's learning log assignment will be posted on Canvas by Thursday. - -Here are the questions you will be asked to answer in the learning logs. - -## Task 1: Formula Sheet - -It is about that time in the course where the number of formulas you have to keep track of is getting large. To help you keep track of the concept and formulas, and to encourage you to reference your own notes during assessments, this week's learning log is about getting you set up with your own formula sheet.  - -I have created a template for you below, but you are NOT required to use it! If you already have your own formula sheet and it's working for you, please continue to use it. - -Keep in mind though, that an ideal formula sheet helps you quickly (i.e. at a glance) find the information you need AND help you remember what you need to do with it. I wish someone had told me that during my undergraduate career!  - -If you have other/better versions that you'd like to share, be my guest (on Piazza)! Though I suggest you not allow others to *edit* your file. Each person should have their own formula sheet. - -[You can access my template and make a copy for yourself here.](https://docs.google.com/document/d/1H9Vyln44eBsdy4SRx9NFQoIbfuIfmVCQDyr-dUKxPYM/copy) - -## Task 2: Renew your vows - -Each week, I am asking you to type out the integrity pledge, letter by letter, so you understand how important it is to me that you maintain your academic integrity as you go through this course. - - - -## Task 3: Well-being check - -One of my goals this year is to help you (as best I can) manage your stress and anxieties by "measuring it" on a weekly basis and intervening or making suggestions during our weekly class meeting. -This is an exciting time for all of you as many of you are starting your undergraduate studies. -With this new excitement, you may be feeling additional stress and anxiety as you learn to manage this new life with its drastic changes, that too in the middle of a pandemic. -In terms of providing support for you as an instructor I’d like for us to measure/rate your anxiety and stress levels - I understand that you may not know what level of stress and/or anxiety is appropriate at this level of your education so feel free to note that! - -Q1: On a scale of 1-10, rate your CURRENT level of anxiety and stress: - -Anxiety: 1-10 -Stress: 1-10 - -Q2: On a scale of 1-10, rate WHERE DO YOU THINK YOUR level of anxiety and stress SHOULD BE: - -Anxiety: 1-10 -Stress: 1-10 - -Q3: Is there anything else you would like to tell me? - -[Open Text] - -I’ll do what I can within my role as an instructor, in terms of workload and due dates. -Part of undergraduate life and healthy living is finding ways to manage your stress and anxiety in a manner that is effective for you - this will look different for each person! -If you want to explore additional resources, start with the ones listed at [UBCV Health and wellbeing](https://students.ubc.ca/health) and see if the tips there work for you! - -Finally, remember (from the course syllabus): as I'm sure you're aware, *there is a global pandemic* happening right now and we could all use some extra compassion and humanity. -If you're going through something that is affecting you (course or otherwise), you are always welcome to come and talk to me about it. -If I am not able to help you myself, then I can probably direct you to the right person or resource. \ No newline at end of file diff --git a/notes/week04/lecture.md b/notes/week04/lecture.md deleted file mode 100644 index 4a95491..0000000 --- a/notes/week04/lecture.md +++ /dev/null @@ -1,15 +0,0 @@ -# Lecture - -This week we will do go over some key clicker questions from Chapter 4 today. - -## Sli.do Polls - -You can go to [https://sli.do/physics111](https://app.sli.do/event/lk89xpvr/live/polls) in a new tab or use the embedded poll here: - - - -## Slides from Lecture - -Will be available here after the lecture. - - \ No newline at end of file diff --git a/notes/week04/readings.md b/notes/week04/readings.md deleted file mode 100644 index 45e6b98..0000000 --- a/notes/week04/readings.md +++ /dev/null @@ -1,30 +0,0 @@ -# Readings - -This week the readings assignments are listed below: - - - - - - - - - - - - - -Click the button below to be taken to the Pearson textbook to access the eText - - -````{card} - -If you have access to the eText, you can go to the eText from here - -```{button-link} https://portal.mypearson.com -Pearson eText -:type: url -:classes: btn-outline-warning btn-block stretched-link text-dark -``` -```` - diff --git a/notes/week04/test.md b/notes/week04/test.md deleted file mode 100644 index 184de91..0000000 --- a/notes/week04/test.md +++ /dev/null @@ -1,11 +0,0 @@ -# Bonus Test 01 - -````{card} - -This week you will have an opportunity to do Bonus Test 01 on Chapters 2 and 3. The Bonus Test will be available from Thursday at 6 PM to Saturday at 6 PM. - -```{button-link} https://canvas.ubc.ca/courses/63995 -Canvas Assignments - -``` -```` \ No newline at end of file diff --git a/notes/week04/videos.md b/notes/week04/videos.md deleted file mode 100644 index 057c818..0000000 --- a/notes/week04/videos.md +++ /dev/null @@ -1,68 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - - - - -``` -```` - -## Required Videos - -Below are the assigned videos for this week. - -### Videos before Tuesday's class - -```{dropdown} 1. Knitting Functions - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 2. Introduction to Pandas - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -### Videos before Thursday's class - -```{dropdown} 3. Data, Internet, and Billboard 100 - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 4. Beautiful Soup - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` \ No newline at end of file diff --git a/notes/week04/week04_summary.md b/notes/week04/week04_summary.md deleted file mode 100755 index 2a37cd5..0000000 --- a/notes/week04/week04_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic4)= -Week 4 Summary -======================= - -This week we will be continuing knitting and learning about Python classes and learning about Pandas. \ No newline at end of file diff --git a/notes/week05/class5A.md b/notes/week05/class5A.md deleted file mode 100644 index 02d1265..0000000 --- a/notes/week05/class5A.md +++ /dev/null @@ -1,27 +0,0 @@ -# Class Meeting 5A - -Below are the slides from today's class embedded. -Feel free to download them to keep them locally, or leave them archived here and just bookmark them. -We will leave the website open even after the course is over for a reasonable number of years. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec09_WebAsData.pdf) - -## Optional links for today - -- [LOTS More on Pandas!]https://firas.moosvi.com/courses/data301/2022_WT2/notes/week05/Class5A/Class5A.html - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week05/class5B.md b/notes/week05/class5B.md deleted file mode 100644 index 27026e7..0000000 --- a/notes/week05/class5B.md +++ /dev/null @@ -1,25 +0,0 @@ -# Class Meeting 5B - -Below are the slides from today's class embedded. -Feel free to download them to keep them locally, or leave them archived here and just bookmark them. -We will leave the website open even after the course is over for a reasonable number of years. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec10_Plotting_DataFrames.pdf) - -## Optional links for today - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week05/homework.md b/notes/week05/homework.md deleted file mode 100644 index e4c2283..0000000 --- a/notes/week05/homework.md +++ /dev/null @@ -1,11 +0,0 @@ -# Homework - -````{card} - -This week the homework assignment is on Chapter 5, and is posted on Mastering physics. - -```{button-link} https://portal.mypearson.com -Mastering Physics - -``` -```` \ No newline at end of file diff --git a/notes/week05/lab.md b/notes/week05/lab.md deleted file mode 100644 index 75a2dce..0000000 --- a/notes/week05/lab.md +++ /dev/null @@ -1,13 +0,0 @@ -# Lab - - -````{card} - -The lab information for this week is in the Physics 111 Lab canvas course... - -```{button-link} https://canvas.ubc.ca/courses/66799 -Physics 111 Lab Canvas -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/week05/learninglogs.md b/notes/week05/learninglogs.md deleted file mode 100644 index 3e53e9b..0000000 --- a/notes/week05/learninglogs.md +++ /dev/null @@ -1,52 +0,0 @@ -# Learning Logs - -This week's learning log assignment will be posted on Canvas by Thursday. - -Here are the questions you will be asked to answer in the learning logs. - -## Task 1: Formula Sheet - -It is about that time in the course where the number of formulas you have to keep track of is getting large. To help you keep track of the concept and formulas, and to encourage you to reference your own notes during assessments, this week's learning log is about getting you set up with your own formula sheet.  - -I have created a template for you below, but you are NOT required to use it! If you already have your own formula sheet and it's working for you, please continue to use it. - -Keep in mind though, that an ideal formula sheet helps you quickly (i.e. at a glance) find the information you need AND help you remember what you need to do with it. I wish someone had told me that during my undergraduate career!  - -If you have other/better versions that you'd like to share, be my guest (on Piazza)! Though I suggest you not allow others to *edit* your file. Each person should have their own formula sheet. - -[You can access my template and make a copy for yourself here.](https://docs.google.com/document/d/1H9Vyln44eBsdy4SRx9NFQoIbfuIfmVCQDyr-dUKxPYM/copy) - -## Task 2: Renew your vows - -Each week, I am asking you to type out the integrity pledge, letter by letter, so you understand how important it is to me that you maintain your academic integrity as you go through this course. - - - -## Task 3: Well-being check - -One of my goals this year is to help you (as best I can) manage your stress and anxieties by "measuring it" on a weekly basis and intervening or making suggestions during our weekly class meeting. -This is an exciting time for all of you as many of you are starting your undergraduate studies. -With this new excitement, you may be feeling additional stress and anxiety as you learn to manage this new life with its drastic changes, that too in the middle of a pandemic. -In terms of providing support for you as an instructor I’d like for us to measure/rate your anxiety and stress levels - I understand that you may not know what level of stress and/or anxiety is appropriate at this level of your education so feel free to note that! - -Q1: On a scale of 1-10, rate your CURRENT level of anxiety and stress: - -Anxiety: 1-10 -Stress: 1-10 - -Q2: On a scale of 1-10, rate WHERE DO YOU THINK YOUR level of anxiety and stress SHOULD BE: - -Anxiety: 1-10 -Stress: 1-10 - -Q3: Is there anything else you would like to tell me? - -[Open Text] - -I’ll do what I can within my role as an instructor, in terms of workload and due dates. -Part of undergraduate life and healthy living is finding ways to manage your stress and anxiety in a manner that is effective for you - this will look different for each person! -If you want to explore additional resources, start with the ones listed at [UBCV Health and wellbeing](https://students.ubc.ca/health) and see if the tips there work for you! - -Finally, remember (from the course syllabus): as I'm sure you're aware, *there is a global pandemic* happening right now and we could all use some extra compassion and humanity. -If you're going through something that is affecting you (course or otherwise), you are always welcome to come and talk to me about it. -If I am not able to help you myself, then I can probably direct you to the right person or resource. \ No newline at end of file diff --git a/notes/week05/lecture.md b/notes/week05/lecture.md deleted file mode 100644 index 7e07ceb..0000000 --- a/notes/week05/lecture.md +++ /dev/null @@ -1,15 +0,0 @@ -# Lecture - -This week we will do go over some key clicker questions from Chapter 5 today. - -## Sli.do Polls - -You can go to [https://sli.do/physics111](https://app.sli.do/event/lk89xpvr/live/polls) in a new tab or use the embedded poll here: - - - -## Slides from Lecture - -Slides are available now, questions with answers will be available here after the lecture. - - \ No newline at end of file diff --git a/notes/week05/readings.md b/notes/week05/readings.md deleted file mode 100644 index 5c03713..0000000 --- a/notes/week05/readings.md +++ /dev/null @@ -1,32 +0,0 @@ -# Readings - -This week the readings assignments are listed below: - - - - - - - - - - - - - - - -Click the button below to be taken to the Pearson textbook to access the eText - - -````{card} - -If you have access to the eText, you can go to the eText from here - -```{button-link} https://portal.mypearson.com -Pearson eText -:type: url -:classes: btn-outline-warning btn-block stretched-link text-dark -``` -```` - diff --git a/notes/week05/test.md b/notes/week05/test.md deleted file mode 100644 index 5004cbc..0000000 --- a/notes/week05/test.md +++ /dev/null @@ -1,11 +0,0 @@ -# Test - -````{card} - -This week will be Test 2, which will be on the contents of Chapter 4 and 5. - -```{button-link} https://canvas.ubc.ca -Canvas - -``` -```` \ No newline at end of file diff --git a/notes/week05/videos.md b/notes/week05/videos.md deleted file mode 100644 index 4abea32..0000000 --- a/notes/week05/videos.md +++ /dev/null @@ -1,131 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - - -``` -```` - -## Required Videos - -Below are the assigned videos for this week. - -### Videos before Tuesday's class - -```{dropdown} 1. Data, Internet, and Billboard 100 - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 2. Beautiful Soup - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` -### Videos before Thursday's class - -```{dropdown} 3. Dataframe Filtering - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 4. Pandas and Dates - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 5. Plotting with Pandas - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -## Optional Videos - -```{dropdown} Pandas in Data Science Tutorial - :class-container: sd-shadow-lg - :color: primary - -Some of you have asked me for advanced Pandas tutorials for your own side-projects and other courses. -Though much of this content is beyond the scope of this course, here is a nice video that I assign to students in one of my other data science courses that might be useful for you. - -Here is an outline of the timestamps of this video (clickable links in the [YouTube Video description](https://www.youtube.com/watch?v=vmEHCJofslg&feature=emb_title)) - -- 0:00 - Why Pandas? -- 1:46 - Installing Pandas -- 2:03 - Getting the data used in this video -- 3:50 - Loading the data into Pandas (CSVs, Excel, TXTs, etc.) -- 8:49 - Reading Data (Getting Rows, Columns, Cells, Headers, etc.) -- 13:10 - Iterate through each Row -- 14:11 - Getting rows based on a specific condition -- 15:47 - High Level description of your data (min, max, mean, std dev, etc.) -- 16:24 - Sorting Values (Alphabetically, Numerically) -- 18:19 - Making Changes to the DataFrame -- 18:56 - Adding a column -- 21:22 - Deleting a column -- 22:14 - Summing Multiple Columns to Create new Column. -- 24:14 - Rearranging columns -- 28:06 - Saving our Data (CSV, Excel, TXT, etc.) -- 31:47 - Filtering Data (based on multiple conditions) -- 35:40 - Reset Index -- 37:41 - Regex Filtering (filter based on textual patterns) -- 43:08 - Conditional Changes -- 47:57 - Aggregate Statistics using Groupby (Sum, Mean, Counting) -- 54:53 - Working with large amounts of data (setting chunksize) - -You can download the [`pokemon.csv` dataset here](https://github.com/firasm/bits/raw/master/pokemon.csv) and [this notebook here](https://github.com/ubco-cmps/data301_course/raw/main/notes/week05/week05_pokemon.ipynb). - -
- -
-``` - - -```{dropdown} 5. Seaborn - :class-container: sd-shadow-lg - :color: primary - -You can see the associated [Jupyter Notebook here](https://firas.moosvi.com/courses/data301/2022_WT2/notes/week06/Class6B/Class6B.html) - -
- -
-``` \ No newline at end of file diff --git a/notes/week05/week05_summary.md b/notes/week05/week05_summary.md deleted file mode 100755 index 82de899..0000000 --- a/notes/week05/week05_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic5)= -Week 5 Summary -======================= - -This week we will start working with some data, using the BeautifulSoup, and parsing data from the internet! \ No newline at end of file diff --git a/notes/week06/Class8C/Class8C.ipynb b/notes/week06/Class8C/Class8C.ipynb deleted file mode 100644 index 26eb2b5..0000000 --- a/notes/week06/Class8C/Class8C.ipynb +++ /dev/null @@ -1,509 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "slideshow": { - "slide_type": "skip" - }, - "tags": [ - "remove-cell" - ] - }, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from IPython.display import IFrame\n", - "from IPython.display import Markdown\n", - "\n", - "# Additional styling ; should be moved into helpers\n", - "from IPython.display import display, HTML\n", - "\n", - "HTML(\"\".format(open(\"rise.css\").read()))" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "# Class 8C. Version Control with Git\n", - "\n", - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Lecture Outline" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "**1. Announcements (2 mins)**" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**2.Version Control with git? (3 mins)**" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**3. The GitHub flow (5 mins)**" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**4. Introduction to Branches and Pull Requests (10 mins)**" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**5. Guided Activity: Create a Branch, submit a Pull Request (25 mins)**" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Request for Volunteers !\n", - "\n", - "- You don't need to have any prior experience, nor do you have to be a computer pro.\n", - "- Probably will just ask you to share your screen and follow directions.\n", - "- I'll walk you through what you have to type and click and hopefully it's illustrative what needs to be done.\n", - "- You don't need to be a computer or git expert!\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## 2. Version Control with Git" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "### Why Git?\n", - "\n", - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "subslide" - } - }, - "source": [ - "## What is Git?\n", - "\n", - "\n", - "\n", - "Image Source: [Noble Desktop](https://www.nobledesktop.com/blog/what-is-git-and-why-should-you-use-it)." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Revisiting Learn Git Branching\n", - "\n", - "" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## The GitHub Flow" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "slideshow": { - "slide_type": "fragment" - }, - "tags": [ - "hide-input" - ] - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "IFrame(\n", - " \"https://enterprise.github.com/downloads/en/github-flow-cheatsheet.pdf\",\n", - " width=1200,\n", - " height=800,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "## GitHub Guides\n", - "\n", - "See this link for lots more about using GitHub: https://github.com/git-guides" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Guided Activity: Create and resolve a merge conflict\n", - "\n", - "1. Message your group mates and get in touch with them\n", - "\n", - "2. ONE PERSON IN EACH ROOM, will fork this repository onto your own GitHub account\n", - "\n", - "3. Clone that fork onto your computer\n", - "\n", - "4. Add your teammates to the repository\n", - "\n", - "5. Teammates clone onto computer\n", - "\n", - "6. Try to create and resolve a merge conflict." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Lecture Outline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**1. Announcements and Recap (5 mins)**" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Part 1. Announcements (5 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Part 2. Introduction to Branches and Pull Requests (20 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "### Create and switch to a new branch\n", - "\n", - "To checkout a new branch that **doesn't already exist**, use:\n", - "\n", - "```\n", - "git switch -c new_branch_name\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "### Switch to an existing branch\n", - "\n", - "To switch to a new branch that **already exists**, use:\n", - "\n", - "```\n", - "git switch branch_name\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "## Part 3. Guided Activity: Create a Branch, submit a Pull Request (20 mins)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "**- Important! Use your Group Project repo**\n", - "\n", - "Partner 1: \"Contributor 1\"\n", - "\n", - "Partner 2: \"Contributor 2\"\n", - "\n", - "Partner 3: Contributor 3\"\n", - "\n", - "- Partner 1 Creates and switches to a new branch:\n", - "\t- git switch -c newchange1\n", - "\n", - "- Partner 2 Creates and switches to a new branch:\n", - "\t- git switch -c newchange2\n", - "\n", - "- Partner 3 Creates and switches to a new branch:\n", - "\t- git switch -c newchange3\n", - " \n", - "- All partners make sure the branch is switched:\n", - "\t- git status\n", - "\n", - "- Partner 2 creates a new md file:\n", - "\t- code newfile.md\n", - "\t- Write a bunch of stuff\n", - "\t- Save\n", - "\t- git add .\n", - "\t- git commit -m \"new change\"\n", - "\t- git push\n", - "\n", - "- Partner 2 goes to the Github.com repo,\n", - "\t- Click \"Compare and Pull Request\"\n", - "\t- Request a review from Partner 1 and Partner 3\n", - "\t- Submit Pull Request\n", - " \n", - "- Partner 3 does the same thing as above" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "source": [ - "### Tips\n", - "Here are some command sequences that might be useful:\n", - "\n", - "```\n", - "- git switch -c 'person1'\n", - "- git switch -c 'person2'\n", - "- edit the file\n", - "- add, commit, push\n", - "- deal with the Pull Request(PR) on GitHub\n", - "```" - ] - } - ], - "metadata": { - "celltoolbar": "Slideshow", - "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.10.2" - }, - "vscode": { - "interpreter": { - "hash": "4a3006030bc8f073e17f416a7c98291111bc2dc23e3286a5e86c679c75d3e5ba" - } - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/notes/week06/Class8C/rise.css b/notes/week06/Class8C/rise.css deleted file mode 100644 index c3a7dfb..0000000 --- a/notes/week06/Class8C/rise.css +++ /dev/null @@ -1,80 +0,0 @@ -/* ---------- markdown cells - */ -body.rise-enabled div.inner_cell>div.text_cell_render.rendered_html { - font-size: 120%; -} - - -/* ---------- code blocks inside markdown - i.e. within ``` lines, or 4-space indented - */ -div.inner_cell>div.text_cell_render.rendered_html>pre { - margin: 0px; -} - -/* ----------- code to remove space above markdown headers - */ -div.inner_cell>div.text_cell_render.rendered_html h1 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h2 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h3 { - margin-top: 0px; -} -div.inner_cell>div.text_cell_render.rendered_html h4 { - margin-top: 0px; -} - -div.inner_cell>div.text_cell_render.rendered_html>pre>code { - font-size: 70%; -} - -/* ---------- tables (from SO) - */ -.rendered_html table, .rendered_html th, .rendered_html tr, .rendered_html td { - font-size: 120%; -} - -/* ---------- Left part of code cells - from this SO answer: https://stackoverflow.com/a/47263575; - /* Narrow the prompts */ -div.prompt_container { - min-width: 5ex; -} -/* Hide prompts altogether for non-code cells */ -.cell:not(.code_cell) .prompt { - display: none; -} -/* ---------- Width of cells - */ -.container { - width:95% !important; -} - - -/* ---------- Vertical Whitespace - */ -.vspace { - margin-top:50px; -} -/* -div.cell.code_cell.rendered.selected, { - border-width:10px; - border-style:solid; - border-color:red; -} */ - - -/* Removes the border of cells */ - -div.cell { - border-width:0px; -} - -/* Increases the thickness of the blue and green (whether or not the cell is selected */ - -div.cell.selected:before; .edit_mode div.cell.selected:before { - width: 20px; -} diff --git a/notes/week06/class6A.md b/notes/week06/class6A.md deleted file mode 100644 index 316727d..0000000 --- a/notes/week06/class6A.md +++ /dev/null @@ -1,92 +0,0 @@ -# Class Meeting 6A - -Below are the slides from today's class embedded. -Feel free to download them to keep them locally, or leave them archived here and just bookmark them. -We will leave the website open even after the course is over for a reasonable number of years. - -Today in class we will be doing a few demos of practical uses of git and version control. -For a good experience, you should come to class with your group mates, and sit close together. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec11_Git_VersionControl.pdf) - - -## Version Control with Git - - - -- Why git? (3 mins) -- The GitHub flow (5 mins) -- Introduction to Branches and Pull Requests (10 mins) -- Guided Activity 1: Intro to Git and GitHub (25 mins) -- Guided Activity 2: Code Reviews (10 mins) -- Git Summary and Review (15 mins) - -### Why Git - - - -### What is Git? - - - -Image Source: [Noble Desktop](https://www.nobledesktop.com/blog/what-is-git-and-why-should-you-use-it). - -## Learn Git Branching - - - -## Request for Volunteers ! - -- You don't need to have any prior experience, nor do you have to be a computer pro. -- Probably will just ask you to share your screen and follow directions. -- I'll walk you through what you have to type and click and hopefully it's illustrative what needs to be done. -- You don't need to be a computer or git expert! - - -## Guided Activity 1: Intro to Git and GitHub - -You will need to get into a group of 3 for this activity, and it would be best if you all sat together. - -- Contributor 1 -- Contributor 2 -- Contributor 3 - -### Tasks: - -- Get into groups of 3 -- Accept a [**group** GitHub Classroom assignment](https://classroom.github.com/a/-GA1rFkW). -- Clone the repo locally using the Terminal. -- Open the repo in VS Code. -- Contributor 1,2,3 all independently make changes to fix their functions in VS Code -- Contributor 1,2,3 all commit to their repos BUT DO NOT PUSH! - -## Guided Activity 2: Code Reviews - -We'll now do a demo on how to submit a Pull Request, and do a code review. - - -## Useful Git Commands - -Here are some command sequences that might be useful: - -- `git status` -- `git clone ...` -- `git add .` or `git add -A` -- `git commit -m` -- `git switch -c 'person1'` -- `git switch -c 'person2'` -- `git add`, `git commit`, `git push` - -## Important links for today: - -- [GitHub Guide](https://github.com/git-guides) -- [Git Cheatsheet](https://enterprise.github.com/downloads/en/github-flow-cheatsheet.pdf) -- [LearnGitBranching](https://https://learngitbranching.js.org) - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week06/class6B.md b/notes/week06/class6B.md deleted file mode 100644 index 9e7c53e..0000000 --- a/notes/week06/class6B.md +++ /dev/null @@ -1,17 +0,0 @@ -# Class Meeting 6B - -There is no class today - take some time to reflect on the content for this week, do your practice, and take the time to finish up Lab 5 (it's slightly longer this week). - -## Optional links for today - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week06/images/git.jpeg b/notes/week06/images/git.jpeg deleted file mode 100644 index 5d2cda0..0000000 Binary files a/notes/week06/images/git.jpeg and /dev/null differ diff --git a/notes/week06/images/git_model_googledoc.png b/notes/week06/images/git_model_googledoc.png deleted file mode 100644 index e377bc0..0000000 Binary files a/notes/week06/images/git_model_googledoc.png and /dev/null differ diff --git a/notes/week06/images/learn_git_branching.png b/notes/week06/images/learn_git_branching.png deleted file mode 100644 index 25fb327..0000000 Binary files a/notes/week06/images/learn_git_branching.png and /dev/null differ diff --git a/notes/week06/videos.md b/notes/week06/videos.md deleted file mode 100644 index d1e6edb..0000000 --- a/notes/week06/videos.md +++ /dev/null @@ -1,78 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - - - - - -``` -```` -## Required Videos - -```{attention} -To get the most benefit from class on Tuesday, ou will definitely need to have watched these videos BEFORE class on Tuesday! -``` - -```{dropdown} Why Use Git? - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} How Git Works - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} Creating a repository - :class-container: sd-shadow-lg - :color: primary - :open: - - Note: It is important you know how to create a repository for your own personal projects. However in this course, you will always get a "GitHub Classroom link" that will create a repository with some starter code. - -
- -
-``` - -```{dropdown} Staging Files - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} Making Commits - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` \ No newline at end of file diff --git a/notes/week06/week06_summary.md b/notes/week06/week06_summary.md deleted file mode 100755 index ac55004..0000000 --- a/notes/week06/week06_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic6)= -Week 6 Summary -======================= - -This week we will start introducing a new tool in our course, Git and GitHub! \ No newline at end of file diff --git a/notes/week07/homework.md b/notes/week07/homework.md deleted file mode 100644 index d487dc7..0000000 --- a/notes/week07/homework.md +++ /dev/null @@ -1,11 +0,0 @@ -# Homework - -````{card} - -This week the homework assignment is on Chapter 6, and is posted on Mastering physics. - -```{button-link} https://portal.mypearson.com -Mastering Physics - -``` -```` \ No newline at end of file diff --git a/notes/week07/lab.md b/notes/week07/lab.md deleted file mode 100644 index 75a2dce..0000000 --- a/notes/week07/lab.md +++ /dev/null @@ -1,13 +0,0 @@ -# Lab - - -````{card} - -The lab information for this week is in the Physics 111 Lab canvas course... - -```{button-link} https://canvas.ubc.ca/courses/66799 -Physics 111 Lab Canvas -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/week07/learninglogs.md b/notes/week07/learninglogs.md deleted file mode 100644 index 3e53e9b..0000000 --- a/notes/week07/learninglogs.md +++ /dev/null @@ -1,52 +0,0 @@ -# Learning Logs - -This week's learning log assignment will be posted on Canvas by Thursday. - -Here are the questions you will be asked to answer in the learning logs. - -## Task 1: Formula Sheet - -It is about that time in the course where the number of formulas you have to keep track of is getting large. To help you keep track of the concept and formulas, and to encourage you to reference your own notes during assessments, this week's learning log is about getting you set up with your own formula sheet.  - -I have created a template for you below, but you are NOT required to use it! If you already have your own formula sheet and it's working for you, please continue to use it. - -Keep in mind though, that an ideal formula sheet helps you quickly (i.e. at a glance) find the information you need AND help you remember what you need to do with it. I wish someone had told me that during my undergraduate career!  - -If you have other/better versions that you'd like to share, be my guest (on Piazza)! Though I suggest you not allow others to *edit* your file. Each person should have their own formula sheet. - -[You can access my template and make a copy for yourself here.](https://docs.google.com/document/d/1H9Vyln44eBsdy4SRx9NFQoIbfuIfmVCQDyr-dUKxPYM/copy) - -## Task 2: Renew your vows - -Each week, I am asking you to type out the integrity pledge, letter by letter, so you understand how important it is to me that you maintain your academic integrity as you go through this course. - - - -## Task 3: Well-being check - -One of my goals this year is to help you (as best I can) manage your stress and anxieties by "measuring it" on a weekly basis and intervening or making suggestions during our weekly class meeting. -This is an exciting time for all of you as many of you are starting your undergraduate studies. -With this new excitement, you may be feeling additional stress and anxiety as you learn to manage this new life with its drastic changes, that too in the middle of a pandemic. -In terms of providing support for you as an instructor I’d like for us to measure/rate your anxiety and stress levels - I understand that you may not know what level of stress and/or anxiety is appropriate at this level of your education so feel free to note that! - -Q1: On a scale of 1-10, rate your CURRENT level of anxiety and stress: - -Anxiety: 1-10 -Stress: 1-10 - -Q2: On a scale of 1-10, rate WHERE DO YOU THINK YOUR level of anxiety and stress SHOULD BE: - -Anxiety: 1-10 -Stress: 1-10 - -Q3: Is there anything else you would like to tell me? - -[Open Text] - -I’ll do what I can within my role as an instructor, in terms of workload and due dates. -Part of undergraduate life and healthy living is finding ways to manage your stress and anxiety in a manner that is effective for you - this will look different for each person! -If you want to explore additional resources, start with the ones listed at [UBCV Health and wellbeing](https://students.ubc.ca/health) and see if the tips there work for you! - -Finally, remember (from the course syllabus): as I'm sure you're aware, *there is a global pandemic* happening right now and we could all use some extra compassion and humanity. -If you're going through something that is affecting you (course or otherwise), you are always welcome to come and talk to me about it. -If I am not able to help you myself, then I can probably direct you to the right person or resource. \ No newline at end of file diff --git a/notes/week07/lecture.md b/notes/week07/lecture.md deleted file mode 100644 index 423bcc8..0000000 --- a/notes/week07/lecture.md +++ /dev/null @@ -1,15 +0,0 @@ -# Lecture - -This week we will do go over some key clicker questions from Chapter 6. - -## Sli.do Polls - -You can go to [https://sli.do/physics111](https://app.sli.do/event/lk89xpvr/live/polls) in a new tab or use the embedded poll here: - - - -## Slides from Lecture - -Slides are available now, questions with answers will be available here after the lecture. - - \ No newline at end of file diff --git a/notes/week07/readings.md b/notes/week07/readings.md deleted file mode 100644 index f1f4cd8..0000000 --- a/notes/week07/readings.md +++ /dev/null @@ -1,30 +0,0 @@ -# Readings - -This week the readings assignments are listed below: - - - - - - - - - - - - - -Click the button below to be taken to the Pearson textbook to access the eText - - -````{card} - -If you have access to the eText, you can go to the eText from here - -```{button-link} https://portal.mypearson.com -Pearson eText -:type: url -:classes: btn-outline-warning btn-block stretched-link text-dark -``` -```` - diff --git a/notes/week07/test.md b/notes/week07/test.md deleted file mode 100644 index 66ebc07..0000000 --- a/notes/week07/test.md +++ /dev/null @@ -1,11 +0,0 @@ -# Test - -````{card} - -This week is Bonus Test 2, and it will mostly be on the contents of Chapter 4 and 5. - -```{button-link} https://canvas.ubc.ca -Canvas - -``` -```` \ No newline at end of file diff --git a/notes/week07/videos.md b/notes/week07/videos.md deleted file mode 100644 index acb2989..0000000 --- a/notes/week07/videos.md +++ /dev/null @@ -1,224 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -``` -```` - -## Required Videos - -```{dropdown} 1. Introduction to Equilibrium - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0119_lecture_notes_-_introduction_to_equilibrium.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/equilibrium.html) -``` - -```{dropdown} 2. Breaking the Force of Gravity into its Components on an Incline - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0132_lecture_notes_-_breaking_the_force_of_gravity_into_its_components_on_an_incline.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/incline-components.html) -``` - -```{dropdown} 3. Do You Feel Your Weight? A lesson on Apparent Weight - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0165_lecture_notes_-_an_introductory_kinetic_friction_on_an_incline_problem_1.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/apparent-weight.html) -``` - -```{dropdown} 4. Introduction to Static and Kinetic Friction by Bobby - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0124_lecture_notes_-_introduction_to_static_and_kinetic_friction_by_bobby.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/friction-intro.html) -``` - -```{dropdown} 5. Introduction to the Coefficient of Friction - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0125_lecture_notes_-_introduction_to_the_coefficient_of_friction.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/mu-intro.html) -``` - -```{dropdown} 6. Understanding the Force of Friction Equation - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0126_lecture_notes_-_understanding_the_force_of_friction_equation.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/friction-equation.html) -``` - -```{dropdown} 7. Introductory Static Friction on an Incline Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0164_lecture_notes_-_an_introductory_static_friction_on_an_incline_problem.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/static-friction-incline.html) -``` - -```{dropdown} 8. Introductory Kinetic Friction on an Incline Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0165_lecture_notes_-_an_introductory_kinetic_friction_on_an_incline_problem.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/kinetic-friction-incline.html) -``` -```{dropdown} 9. Do Your Feet Affect How Far You Slide on a Water Slide? - :class-container: sd-shadow-lg - :color: primary - -
- -
-- [Direct link to Mr. P's page](https://www.flippingphysics.com/water-slide.html) -``` - -```{dropdown} 10. Deriving the Equation for Terminal Velocity - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -## Optional Videos - -The videos below are relevant to the subject material, but are not required for Physics 111. - -```{dropdown} 11. Physics "Magic Trick" on an Incline - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0133_lecture_notes_-_physics_magic_trick_on_an_incline.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/magic-trick.html) - -``` -```{dropdown} 12. Does the Book Move? An Introductory Friction Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0128_lecture_notes_-_does_the_book_move-_an_introductory_friction_problem.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/friction-problem.html) - -``` -```{dropdown} 13. Do Anti-lock Brakes use Static or Kinetic Friction? by Billy - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0129_lecture_notes_-_do_anti-lock_brakes_use_static_or_kinetic_friction_by_billy.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/abs-brakes.html) - -``` -```{dropdown} 14. A Friction Review Problem - The Original Billy Bobby and Bo - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/04-04_in-class_lecture_notes_-_a_friction_review_problem_-_the_original_billy_bobby_and_bo.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/friction-review-problem.html) - -``` -```{dropdown} 15. Determining the Static Coefficient of Friction between Tires and Snow - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0131_lecture_notes_-_determining_the_static_coefficient_of_friction_between_tires_and_snow.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/tire-friction.html) - -``` diff --git a/notes/week07/week06_summary.md b/notes/week07/week06_summary.md deleted file mode 100755 index 483489e..0000000 --- a/notes/week07/week06_summary.md +++ /dev/null @@ -1,22 +0,0 @@ -(page_topic6)= -Week 6 Summary -======================= - -This week there is no new content (except for your lab) in this course. -This week, you'll have an opportunity to catch your breath and catch up on anything from the last few weeks that you didn't have time to grasp or go through. -This may include test questions, missed homework questions, videos that you didn't watch, readings you didn't do, or anything else. -Though you don't *have to* use this break for Physics work, I encourage you to make sure you are actually caught up before re-purposing that time for other courses. -That being said, I understand it's midterm season so I'm sure you'll have plenty of things to fill your time with. - - -```{dropdown} Portal - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
- -[Link to the game](https://store.steampowered.com/app/400/Portal) -``` \ No newline at end of file diff --git a/notes/week07/week07_summary.md b/notes/week07/week07_summary.md deleted file mode 100755 index fdca5ca..0000000 --- a/notes/week07/week07_summary.md +++ /dev/null @@ -1,22 +0,0 @@ -(page_topic7)= -Week 7 Summary -======================= - -This week there is no new content in this course - it's Reading week! -This week, you'll have an opportunity to catch your breath and catch up on anything from the last few weeks that you didn't have time to grasp or go through. -This may include test questions, missed POTW questions, videos that you didn't watch, activities you didn't finish, or anything else left over. -Though you don't *have to* use this break for CPSC 203, I encourage you to make sure you are actually caught up before re-purposing that time for other courses. - -Here's a fun video from a game I enjoyed playing a lot! - -```{dropdown} Portal - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
- -[Link to the game](https://store.steampowered.com/app/400/Portal) -``` \ No newline at end of file diff --git a/notes/week08/class8A.md b/notes/week08/class8A.md deleted file mode 100644 index 6b07d73..0000000 --- a/notes/week08/class8A.md +++ /dev/null @@ -1,47 +0,0 @@ -# Class Meeting 8A - -Slides will be released before class (sorry!). - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec12_DataStructures.pdf) - -## Important links for today: - -- [Guide to python data structures](https://www.geeksforgeeks.org/python-data-structures/) -- [Deque](https://www.geeksforgeeks.org/deque-in-python/) - - - -## Logistics - -1. Jupyter Lab - -For class today, you will need to install JupyterLab because we'll be using an `.ipynb` file to use the `%%timeit` cell-magic. -You can do this by running the following command in the Terminal: - -``` -conda install -c conda-forge jupyterlab -``` - -You can then run `jupyter lab` in the Terminal to launch a JupyterLab instance. - -2. Clone the Class Activity Repository - -You will first need to "accept" the GitHub Classroom assignment to get a copy of the starter code. - -You can do that by [clicking here](https://classroom.github.com/a/o6D2NVBz). - -Then, clone the `classActivity0XY` repository by running the following line in your Terminal: - -``` -git clone -``` - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week08/class8B.md b/notes/week08/class8B.md deleted file mode 100644 index eb9077a..0000000 --- a/notes/week08/class8B.md +++ /dev/null @@ -1,35 +0,0 @@ -# Class Meeting 8B - -Slides will be released before class (sorry!). - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec13_Voronoi.pdf) - -## Important links for today: - -- [Deque](https://www.geeksforgeeks.org/deque-in-python/) - - - -## Logistics - -1. Clone the Class Activity Repository - -You will first need to "accept" the GitHub Classroom assignment to get a copy of the starter code. - -You can do that by [clicking here](https://classroom.github.com/a/ACntc8CV). - -Then, clone the `classActivity0XY` repository by running the following line in your Terminal: - -``` -git clone -``` - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week08/videos.md b/notes/week08/videos.md deleted file mode 100644 index d88ae6a..0000000 --- a/notes/week08/videos.md +++ /dev/null @@ -1,93 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - - - - - - -``` -```` -## Required Videos - -### Tuesday's Class - - -```{dropdown} 1. What are Data Structures? - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - - -```{dropdown} 2. Introduction to Queues - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - - -### Thursday's class - -```{dropdown} 1. Motivating Voronoi Diagrams - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 2. Computing Voronoi Diagrams - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 3. Queues and Voronoi Diagrams - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -### Optional Videos - -This will be a required video next week (Week 9). - -```{dropdown} 4. Pointilism - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` \ No newline at end of file diff --git a/notes/week08/week08_summary.md b/notes/week08/week08_summary.md deleted file mode 100755 index e7e7e1a..0000000 --- a/notes/week08/week08_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic8)= -Week 8 Summary -======================= - -This week we will talk about some new Data Structures and formalize a language for all the data structures we've seen (and will see)! \ No newline at end of file diff --git a/notes/week09/class9A.md b/notes/week09/class9A.md deleted file mode 100644 index 3082822..0000000 --- a/notes/week09/class9A.md +++ /dev/null @@ -1,36 +0,0 @@ -# Class Meeting 9A - -Today we will be wrapping up our Voronoi Art code and finishing it up. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec14_Voronoi2_Graphs.pdf) - -## Important links for today: - -- [Deque](https://www.geeksforgeeks.org/deque-in-python/) -- [Math Pre-requisite Graph](https://ubcmath.github.io/coursemap/) - - - -## Logistics - -1. Clone the Class Activity Repository - -You will first need to "accept" the GitHub Classroom assignment to get a copy of the starter code. - -You can do that by [clicking here](https://classroom.github.com/a/9O9S8RgF). - -Then, clone the `classActivity0XY` repository by running the following line in your Terminal: - -``` -git clone -``` - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week09/class9B.md b/notes/week09/class9B.md deleted file mode 100644 index 23ff083..0000000 --- a/notes/week09/class9B.md +++ /dev/null @@ -1,38 +0,0 @@ -# Class Meeting 9B - -Today we will be continuing our discussion on Graphs - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec15_Graph_Exploration.pdf) - -## Important links for today: - -- [Graphs Tutorial](https://www.geeksforgeeks.org/introduction-to-graphs-data-structure-and-algorithm-tutorials/?ref=gcse) - - - -## Logistics - -Nothing to clone for today - I think! - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week09/videos.md b/notes/week09/videos.md deleted file mode 100644 index f777f95..0000000 --- a/notes/week09/videos.md +++ /dev/null @@ -1,85 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - - - - -## Required Videos - -### Tuesday's Class - -None! - - -### Thursday's class - -More videos coming soon... - -```{dropdown} 1. Directed Graphs - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 2. Graph Exploration - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - - diff --git a/notes/week09/week09_summary.md b/notes/week09/week09_summary.md deleted file mode 100755 index e360f1a..0000000 --- a/notes/week09/week09_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic9)= -Week 9 Summary -======================= - -This week we will finish up with queues, and then move on to Graphs as a new data structure. \ No newline at end of file diff --git a/notes/week10/homework.md b/notes/week10/homework.md deleted file mode 100644 index 2a1da6e..0000000 --- a/notes/week10/homework.md +++ /dev/null @@ -1,11 +0,0 @@ -# Homework - -````{card} - -This week the homework assignment is on Chapter 9, and is posted on Mastering physics. - -```{button-link} https://portal.mypearson.com -Mastering Physics - -``` -```` \ No newline at end of file diff --git a/notes/week10/lab.md b/notes/week10/lab.md deleted file mode 100644 index 75a2dce..0000000 --- a/notes/week10/lab.md +++ /dev/null @@ -1,13 +0,0 @@ -# Lab - - -````{card} - -The lab information for this week is in the Physics 111 Lab canvas course... - -```{button-link} https://canvas.ubc.ca/courses/66799 -Physics 111 Lab Canvas -:type: url -:classes: btn-outline-primary btn-block stretched-link text-dark -``` -```` \ No newline at end of file diff --git a/notes/week10/learninglogs.md b/notes/week10/learninglogs.md deleted file mode 100644 index 3e53e9b..0000000 --- a/notes/week10/learninglogs.md +++ /dev/null @@ -1,52 +0,0 @@ -# Learning Logs - -This week's learning log assignment will be posted on Canvas by Thursday. - -Here are the questions you will be asked to answer in the learning logs. - -## Task 1: Formula Sheet - -It is about that time in the course where the number of formulas you have to keep track of is getting large. To help you keep track of the concept and formulas, and to encourage you to reference your own notes during assessments, this week's learning log is about getting you set up with your own formula sheet.  - -I have created a template for you below, but you are NOT required to use it! If you already have your own formula sheet and it's working for you, please continue to use it. - -Keep in mind though, that an ideal formula sheet helps you quickly (i.e. at a glance) find the information you need AND help you remember what you need to do with it. I wish someone had told me that during my undergraduate career!  - -If you have other/better versions that you'd like to share, be my guest (on Piazza)! Though I suggest you not allow others to *edit* your file. Each person should have their own formula sheet. - -[You can access my template and make a copy for yourself here.](https://docs.google.com/document/d/1H9Vyln44eBsdy4SRx9NFQoIbfuIfmVCQDyr-dUKxPYM/copy) - -## Task 2: Renew your vows - -Each week, I am asking you to type out the integrity pledge, letter by letter, so you understand how important it is to me that you maintain your academic integrity as you go through this course. - - - -## Task 3: Well-being check - -One of my goals this year is to help you (as best I can) manage your stress and anxieties by "measuring it" on a weekly basis and intervening or making suggestions during our weekly class meeting. -This is an exciting time for all of you as many of you are starting your undergraduate studies. -With this new excitement, you may be feeling additional stress and anxiety as you learn to manage this new life with its drastic changes, that too in the middle of a pandemic. -In terms of providing support for you as an instructor I’d like for us to measure/rate your anxiety and stress levels - I understand that you may not know what level of stress and/or anxiety is appropriate at this level of your education so feel free to note that! - -Q1: On a scale of 1-10, rate your CURRENT level of anxiety and stress: - -Anxiety: 1-10 -Stress: 1-10 - -Q2: On a scale of 1-10, rate WHERE DO YOU THINK YOUR level of anxiety and stress SHOULD BE: - -Anxiety: 1-10 -Stress: 1-10 - -Q3: Is there anything else you would like to tell me? - -[Open Text] - -I’ll do what I can within my role as an instructor, in terms of workload and due dates. -Part of undergraduate life and healthy living is finding ways to manage your stress and anxiety in a manner that is effective for you - this will look different for each person! -If you want to explore additional resources, start with the ones listed at [UBCV Health and wellbeing](https://students.ubc.ca/health) and see if the tips there work for you! - -Finally, remember (from the course syllabus): as I'm sure you're aware, *there is a global pandemic* happening right now and we could all use some extra compassion and humanity. -If you're going through something that is affecting you (course or otherwise), you are always welcome to come and talk to me about it. -If I am not able to help you myself, then I can probably direct you to the right person or resource. \ No newline at end of file diff --git a/notes/week10/lecture.md b/notes/week10/lecture.md deleted file mode 100644 index f1a9fd7..0000000 --- a/notes/week10/lecture.md +++ /dev/null @@ -1,6 +0,0 @@ -# Lecture - -This week the lecture is CANCELLED due to the Remembrance Day Holiday. - -There will be an OPTIONAL makeup class on Monday or Tuesday the following week. -It will be recorded. \ No newline at end of file diff --git a/notes/week10/readings.md b/notes/week10/readings.md deleted file mode 100644 index 6e7df5f..0000000 --- a/notes/week10/readings.md +++ /dev/null @@ -1,30 +0,0 @@ -# Readings - -This week the readings assignments are listed below: - - - - - - - - - - - - - -Click the button below to be taken to the Pearson textbook to access the eText - - -````{card} - -If you have access to the eText, you can go to the eText from here - -```{button-link} https://portal.mypearson.com -Pearson eText -:type: url -:classes: btn-outline-warning btn-block stretched-link text-dark -``` -```` - diff --git a/notes/week10/test.md b/notes/week10/test.md deleted file mode 100644 index 9221b81..0000000 --- a/notes/week10/test.md +++ /dev/null @@ -1,11 +0,0 @@ -# Test - -````{card} - -This week is a Test, and it will mostly be on the contents of Chapter 8 and 9. - -```{button-link} https://canvas.ubc.ca -Canvas - -``` -```` \ No newline at end of file diff --git a/notes/week10/videos.md b/notes/week10/videos.md deleted file mode 100644 index 6c39556..0000000 --- a/notes/week10/videos.md +++ /dev/null @@ -1,187 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip - - - - - - - - - - - - - - - - - - - - - - - - -``` -```` - -## Content Summary from Crash Course Physics - -```{dropdown} Work, Energy, and Power - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -## Required Videos - -```{dropdown} 1. Introduction to Work with Examples - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0134_lecture_notes_-_introduction_to_work_with_examples.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/work-intro.html) -``` - -```{dropdown} 2. Introductory Work Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0137_lecture_notes_-_introductory_work_problem.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/work-problem.html) -``` - -```{dropdown} 3. Introduction to Kinetic Energy with Example Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0138_lecture_notes_-_introduction_to_kinetic_energy_with_example_problem.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/intro-ke.html) -``` - -```{dropdown} 4. Introduction to the Integral or Anti-Derivative for use in Work from a Non-Constant Force - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -```{dropdown} 5. Defining Work with the Dot Product and a Review of the Dot Product - Constant Force - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -```{dropdown} 6. Hooke's Law Introduction - Force of a Spring - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0248_lecture_notes_-_hookes_law_introduction_-_force_of_a_spring.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/hookes-law.html) -``` - -```{dropdown} 7. Determining the Spring Constant, k, with a Vertically Hanging Mass - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0249_lecture_notes_-_determining_the_spring_constant_k_with_a_vertically_hanging_mass.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/vertical-spring-constant.html) -``` - -```{dropdown} 8. The Human Spine acts like a Compression Spring - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0250_lecture_notes_-_the_human_spine_acts_like_a_compression_spring.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/horizontal-spring-constant.html) -``` - -```{dropdown} 9. Introduction to Mechanical Energy with Friction - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0145_lecture_notes_-_introduction_to_mechanical_energy_with_friction.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/intro-wf.html) -``` - -```{dropdown} 10. Introductory Work due to Friction equals Change in Mechanical Energy Problem - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0148_lecture_notes_-_introductory_work_due_to_friction_equals_change_in_mechanical_energy_problem.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/intro-wf-problem.html) -``` - -```{dropdown} 11. Introduction to Power - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0162_lecture_notes_-_introduction_to_power.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/power.html) -``` - -```{dropdown} 12. Average and Instantaneous Power Example - :class-container: sd-shadow-lg - :color: primary - -
- -
- -- [Notes](https://www.flippingphysics.com/uploads/2/1/1/0/21103672/0163_lecture_notes_-_average_and_instantaneous_power_example.pdf) -- [Direct link to Mr. P's page](https://www.flippingphysics.com/power-example.html) -``` diff --git a/notes/week10/week10_summary.md b/notes/week10/week10_summary.md deleted file mode 100755 index 43cca4d..0000000 --- a/notes/week10/week10_summary.md +++ /dev/null @@ -1,23 +0,0 @@ -(page_topic10)= -Week 10 Summary -======================= - -## List of things to do this week - -Below is a list of things you need to do this week, links to where you can do them, as well as roughly the order you should do it. -Note that these are just SUGGESTIONS and you are by no means required to them this way. -I have put the labs at the end, but if your lab section is earlier in the week, you may want to shift things around to accommodate that. - - - - - - - - - - - - - - \ No newline at end of file diff --git a/notes/week11/class11A.md b/notes/week11/class11A.md deleted file mode 100644 index eebae29..0000000 --- a/notes/week11/class11A.md +++ /dev/null @@ -1,36 +0,0 @@ -# Class Meeting 11A - -Today we will be working on creating some music (and later linking it back to Graphs)! - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec16_MHall.pdf) - -## Important links for today: - -- [Markov Chains Demo](http://setosa.io/markov) -- [Markov Chains](https://brilliant.org/wiki/markov-chains/) - - - -## Logistics - -1. Clone the Class Activity Repository - -You will first need to "accept" the GitHub Classroom assignment to get a copy of the starter code. - -You can do that by [clicking here](https://classroom.github.com/a/ShgbwvAQ). - -Then, clone the `classActivity1XY` repository by running the following line in your Terminal: - -``` -git clone -``` - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week11/class11B.md b/notes/week11/class11B.md deleted file mode 100644 index a4f00fa..0000000 --- a/notes/week11/class11B.md +++ /dev/null @@ -1,36 +0,0 @@ -# Class Meeting 11B - -Today's class is cancelled so you have some time to get started on Project 2. -One of our TAs, Minh, has made a video to help you get started if you're stuck. - -```{dropdown} 1. Introduction to Project 2 - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - - -## Logistics - -Nothing to clone for today - I think! - - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week11/videos.md b/notes/week11/videos.md deleted file mode 100644 index f5a4e41..0000000 --- a/notes/week11/videos.md +++ /dev/null @@ -1,85 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - - - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - -``` -```` - - -## Required Videos - -### Tuesday's Class - -```{dropdown} 1. Music Generation - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -### Thursday's class - -```{dropdown} 1. Introduction to Project 2 - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - - - - diff --git a/notes/week11/week11_summary.md b/notes/week11/week11_summary.md deleted file mode 100755 index cb9178f..0000000 --- a/notes/week11/week11_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic11)= -Week 11 Summary -======================= - -This week we will continue our discussion on Graphs and look at two examples of them with code. \ No newline at end of file diff --git a/notes/week12/class12A.md b/notes/week12/class12A.md deleted file mode 100644 index 18977c6..0000000 --- a/notes/week12/class12A.md +++ /dev/null @@ -1,36 +0,0 @@ -# Class Meeting 12A - -Today we will be working on understanding and exploring the Depth-first algorithm. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec18_StateSpaces.pdf) - -## Important links for today: - -- [Solve a Sudoku puzzle](https://www.sudokuonline.io/kids/numbers-4-4) -- [Mathematics of Sudoku](https://en.wikipedia.org/wiki/Mathematics_of_Sudoku) - - - -## Logistics - -1. Clone the Class Activity Repository - -You will first need to "accept" the GitHub Classroom assignment to get a copy of the starter code. - -You can do that by [clicking here](https://classroom.github.com/a/ZEaSSumI). - -Then, clone the `classActivity1XY` repository by running the following line in your Terminal: - -``` -git clone -``` - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week12/class12B.md b/notes/week12/class12B.md deleted file mode 100644 index 54fd88f..0000000 --- a/notes/week12/class12B.md +++ /dev/null @@ -1,41 +0,0 @@ -# Class Meeting 12B - -Today we will be try to find the shortest path through some graphs. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec18_Maps.pdf) - -## Important links for today: - -- [Solving Dijkstra's Algorithm](https://algo-dijkstra.vercel.app/index.html) -- [Dijkstra's Algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) -- [Graphical explanation of Dijkstra's algorithm](https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/) -- [Another graphical explanation of Dijkstra's algorithm](https://www.freecodecamp.org/news/dijkstras-shortest-path-algorithm-visual-introduction/) - - - -## Logistics - -There is no repo to clone today! - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week12/videos.md b/notes/week12/videos.md deleted file mode 100644 index 0e0f230..0000000 --- a/notes/week12/videos.md +++ /dev/null @@ -1,104 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - - - - - - -``` -```` - -## Required Videos - -### Tuesday's Class - -```{dropdown} 1. Searching State Spaces - Depth First Search - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 2. Depth First Search Part 2 - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -```{dropdown} 3. Stacks and Breadth-first search - :class-container: sd-shadow-lg - :color: primary - -
- -
-``` - -### Thursday's class - -We'll continue the stuff from Tuesday on Thursday. - - -```{dropdown} 4. Single Source Shortest Path - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -```{dropdown} 5. Dijkstra's Algorithm - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - - diff --git a/notes/week12/week12_summary.md b/notes/week12/week12_summary.md deleted file mode 100755 index 890ae18..0000000 --- a/notes/week12/week12_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic12)= -Week 12 Summary -======================= - -This week we will are talking about State Spaces, and diving deeper into Graphs. \ No newline at end of file diff --git a/notes/week13/class13A.md b/notes/week13/class13A.md deleted file mode 100644 index 11b01fc..0000000 --- a/notes/week13/class13A.md +++ /dev/null @@ -1,48 +0,0 @@ -# Class Meeting 13A - -Today we will be working on using Maps. - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec19_Maps2.pdf) - -## Important links for today: - -- [Solve a Sudoku puzzle](https://www.sudokuonline.io/kids/numbers-4-4) -- [Mathematics of Sudoku](https://en.wikipedia.org/wiki/Mathematics_of_Sudoku) - - - -## Logistics - -### Installing packages - -You will probably need to install some packages for today's class: - -- `conda install osmnx` -- `conda install networkx` -- `conda install folium` -- `conda install scikit-learn` -- `conda install mapclassify` - -### Cloning a repository - -1. Clone the Class Activity Repository - -You will first need to "accept" the GitHub Classroom assignment to get a copy of the starter code. - -You can do that by [clicking here](https://classroom.github.com/a/qYP0az4U). - -Then, clone the `classActivity1XY` repository by running the following line in your Terminal: - -``` -git clone -``` - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week13/class13B.md b/notes/week13/class13B.md deleted file mode 100644 index 22bc6e0..0000000 --- a/notes/week13/class13B.md +++ /dev/null @@ -1,36 +0,0 @@ -# Class Meeting 13B - -Today we will be working on the Travelling Salesperson problem (the slides are the same as 13A). - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec19_Maps2.pdf) - - - -## Logistics - - 1. Clone the Class Activity Repository - -You will first need to "accept" the GitHub Classroom assignment to get a copy of the starter code. - -You can do that by [clicking here](https://classroom.github.com/a/LXKH9ZuB). - -Then, clone the `classActivity1XY` repository by running the following line in your Terminal: - -``` -git clone -``` - - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week13/videos.md b/notes/week13/videos.md deleted file mode 100644 index ea9fb46..0000000 --- a/notes/week13/videos.md +++ /dev/null @@ -1,55 +0,0 @@ -# Videos - -Below are the assigned videos for this week. -The videos are collapsible so once you're done with one, you can move to the next one. -In the sidebar on the right, you can use the checklists to keep track of what's done. - -````{margin} -```{admonition} Checklist of items -:class: tip sticky - - - -``` -```` - -## Required Videos - -### Tuesday's Class - -```{dropdown} 1. Geographical Applications of Maps - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - -### Thursday's class - -The Travelling Salesperson problem (TSP). - -```{dropdown} 2. Travelling Salesperson problem - :class-container: sd-shadow-lg - :color: primary - :open: - -
- -
-``` - - diff --git a/notes/week13/week13_summary.md b/notes/week13/week13_summary.md deleted file mode 100755 index 6adf301..0000000 --- a/notes/week13/week13_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic13)= -Week 13 Summary -======================= - -This week we will be working with Maps data, a natural application of Graphs. \ No newline at end of file diff --git a/notes/week14/class14A.md b/notes/week14/class14A.md deleted file mode 100644 index e863bde..0000000 --- a/notes/week14/class14A.md +++ /dev/null @@ -1,44 +0,0 @@ -# Class Meeting 14A - -Today we will be working on visualizing literature - -
- -
- -[Download the Slides from today](https://github.com/ubc-cs/cpsc203/raw/main/files/Lec20_LitViz.pdf) - -## Important links for today: - -- [Solve a Sudoku puzzle](https://www.sudokuonline.io/kids/numbers-4-4) -- [Mathematics of Sudoku](https://en.wikipedia.org/wiki/Mathematics_of_Sudoku) - - - -## Logistics - -### Installing packages - -You will probably need to install some packages for today's class: - -- `conda install nltk` - -### Cloning a repository - -1. Clone the Class Activity Repository - -You will first need to "accept" the GitHub Classroom assignment to get a copy of the starter code. - -You can do that by [clicking here](https://classroom.github.com/a/QOTyz_JX). - -Then, clone the `classActivity1XY` repository by running the following line in your Terminal: - -``` -git clone -``` - -## Acknowledgements - -Slides for {{ COURSE_CODE }} were developed and created by [Dr. Cinda Heeren](https://www.cs.ubc.ca/people/cinda-heeren). The current iteration of the course resulted in minor adaptations and updates, but by in large, full credit of these slides belongs to Dr. Cinda Heeren. \ No newline at end of file diff --git a/notes/week14/week14_summary.md b/notes/week14/week14_summary.md deleted file mode 100755 index bf2af66..0000000 --- a/notes/week14/week14_summary.md +++ /dev/null @@ -1,5 +0,0 @@ -(page_topic14)= -Week 14 Summary -======================= - -This week we will be demoing some cool examples of Graph Applications. \ No newline at end of file