From 2dc035e5b395c45e4ee37597141a28500f86b025 Mon Sep 17 00:00:00 2001 From: "Marte M. Vroom" Date: Sun, 15 Mar 2026 21:09:41 -0400 Subject: [PATCH 1/2] Assignment 1 submission --- 01_materials/slides/01_data_types.ipynb | 34 +- File-1.ipynb | 1448 +++++++++++++++++++++++ File-2.ipynb | 1163 ++++++++++++++++++ assignment-1.ipynb | 201 ++++ 4 files changed, 2840 insertions(+), 6 deletions(-) create mode 100644 File-1.ipynb create mode 100644 File-2.ipynb create mode 100644 assignment-1.ipynb diff --git a/01_materials/slides/01_data_types.ipynb b/01_materials/slides/01_data_types.ipynb index a19f3d709..20142059b 100644 --- a/01_materials/slides/01_data_types.ipynb +++ b/01_materials/slides/01_data_types.ipynb @@ -40,9 +40,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "5 + 6" ] @@ -61,9 +72,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2.5" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "5 / 2" ] @@ -318,7 +340,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "python-env", "language": "python", "name": "python3" }, @@ -332,7 +354,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" } }, "nbformat": 4, diff --git a/File-1.ipynb b/File-1.ipynb new file mode 100644 index 000000000..248f9eb07 --- /dev/null +++ b/File-1.ipynb @@ -0,0 +1,1448 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "3b9de9a8", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "id": "55d2c4ec", + "metadata": {}, + "source": [ + "March 4th, 2026" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "1fde1d91", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2 + 2" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "2c58483e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 + 6" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b6e7d3e2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 + 6" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "6a674543", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 + 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0239134b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "bcb2e599", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4 + 4" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "82eb6e53", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello!\n" + ] + } + ], + "source": [ + "print(\"Hello!\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47e14c36", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 + 6 # int -> whole numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c452f8cf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "23.1" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "11.0 + 12.1 # float -> decimal number" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5c2c99aa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.3333333333333335" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 / 3" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "96d07e81", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "10 // 3 # integer division -> divide first operand by second & return quotient rounded down to nearest integer" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "17861c8a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# modulo operator\n", + "# return the remainder of the division of the first operand by the second\n", + "10 % 3" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "0340c871", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1000" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# exponentiation\n", + "# raising a number to a power\n", + "\n", + "10 ** 3" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "6abb5a76", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# bool\n", + "# True or False\n", + "\n", + "50 > 25" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "e6707660", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-15 >= -14.99" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "3f61f4eb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 == 20" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "a91221ec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "20 != 20" + ] + }, + { + "cell_type": "markdown", + "id": "fbdd4b8d", + "metadata": {}, + "source": [ + "# Header 1\n", + "\n", + "## Header 2" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "8f7cafda", + "metadata": {}, + "outputs": [], + "source": [ + "# negation: unary operation that chages the sign of a number\n", + "# substraction: binary oepration, substract one value from another" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "d3a1b6f3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4 - 3" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "6e253dbe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-5" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-5" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c32b524d", + "metadata": {}, + "outputs": [], + "source": [ + "# variable names\n", + "\n", + "# letters, digits, and underscores\n", + "# cannot start with a digit\n", + "# case sensitive" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "5237eb14", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 25" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "8cc493e9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius " + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "16374149", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_fahrenheit = (9 / 5) * degrees_celsius + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "9491f4f2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "950f6f66", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(9 / 5) * 25 + 32" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "ae4a4642", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = 0" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "87eddad2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "77.0" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "c5bb26e8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "e06a82e7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_fahrenheit" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1c7c8a6f", + "metadata": {}, + "outputs": [], + "source": [ + "degrees_celsius = degrees_celsius + 10 # 0 + 10 = 10" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "ae22b17d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "degrees_celsius" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "adc541c2", + "metadata": {}, + "outputs": [], + "source": [ + "a = 1" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "ff9c333e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "1a1a064a", + "metadata": {}, + "outputs": [], + "source": [ + "b = a" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "a2636756", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "baa14239", + "metadata": {}, + "outputs": [], + "source": [ + "a = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "7cb1fe86", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "ab8f0022", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "e6173afd", + "metadata": {}, + "outputs": [], + "source": [ + "no_of_weeks = 4" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "5d64eeb5", + "metadata": {}, + "outputs": [], + "source": [ + "no_of_weeks = no_of_weeks + 10 # 4 + 10 = 14" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "d588509f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "no_of_weeks" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "d9d8900c", + "metadata": {}, + "outputs": [], + "source": [ + "# augmented assignment" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b53b7177", + "metadata": {}, + "outputs": [], + "source": [ + "no_of_weeks += 10 # 14 + 10 = 24" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "bb97fdb5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "no_of_weeks" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "6115c4d8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n" + ] + } + ], + "source": [ + "print(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "59b7b2e4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "087937ae", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "43" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abs(-43)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "0d9fbf82", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(3.99)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "50ccbb6e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7.0" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float(7)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "812d4241", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3)" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "04075c25", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2/3" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "4718b9ed", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on built-in function round in module builtins:\n", + "\n", + "round(number, ndigits=None)\n", + " Round a number to a given precision in decimal digits.\n", + " \n", + " The return value is an integer if ndigits is omitted or None. Otherwise\n", + " the return value has the same type as the number. ndigits may be negative.\n", + "\n" + ] + } + ], + "source": [ + "help(round)" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "1c76cd6d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6667" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3, 4)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1572ceae", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "24\n" + ] + } + ], + "source": [ + "# nested function\n", + "\n", + "print(round(abs(-16) * 1.5))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "365b8f87", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " degrees_f = (9 / 5) * degrees_c + 32\n", + " return degrees_f" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "e910f6e6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "7a395243", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "91.4" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(33)" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "id": "dc17ad39", + "metadata": {}, + "outputs": [], + "source": [ + "# parameters\n", + "# placeholders for the values that will be provided when the function is called\n", + "# local variables within the function, only accessible inside function's code block\n", + "\n", + "# argument\n", + "# actual value that is passed to the function when it is called\n", + "# correspond to the parameters in the function definition and provide the data for the\n", + "# function to work on" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "07a5466c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.2" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(-11)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "002ab7cd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "bda4d2dd", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'degrees_c' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[57]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mdegrees_c\u001b[49m\n", + "\u001b[31mNameError\u001b[39m: name 'degrees_c' is not defined" + ] + } + ], + "source": [ + "degrees_c" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "d16df567", + "metadata": {}, + "outputs": [], + "source": [ + "weather_today = 100" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "fad45cf9", + "metadata": {}, + "outputs": [], + "source": [ + "def divide(dividend, diviser):\n", + " output = dividend / diviser\n", + " return output" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "339b5d68", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "20.0" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "divide(100, 5)" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "b6cfdded", + "metadata": {}, + "outputs": [ + { + "ename": "ZeroDivisionError", + "evalue": "division by zero", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mZeroDivisionError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[61]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mdivide\u001b[49m\u001b[43m(\u001b[49m\u001b[32;43m100\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[59]\u001b[39m\u001b[32m, line 2\u001b[39m, in \u001b[36mdivide\u001b[39m\u001b[34m(dividend, diviser)\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mdivide\u001b[39m(dividend, diviser):\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m output = \u001b[43mdividend\u001b[49m\u001b[43m \u001b[49m\u001b[43m/\u001b[49m\u001b[43m \u001b[49m\u001b[43mdiviser\u001b[49m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m output\n", + "\u001b[31mZeroDivisionError\u001b[39m: division by zero" + ] + } + ], + "source": [ + "divide(100, 0)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "1ae89c68", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_sales_tax(price, tax_rate=0.13):\n", + " tax_amt = price * tax_rate\n", + " return tax_amt" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "e3018c37", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.9500000000000002" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sales_tax(15)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "5c9d2d1c", + "metadata": {}, + "outputs": [], + "source": [ + "def calc_total_bill(price, tax_rate=0.13, tip_rate=0.15):\n", + " tax_amt = price * tax_rate\n", + " tip_amt = price * tip_rate\n", + " return price + tax_amt + tip_amt" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "6d546c27", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "128.0" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "2337c591", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "133.0" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100, 0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "5c6ece1a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "102.7" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "100 + 100 * 0.18 * 0.15" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "d2dac24b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "131.0" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_total_bill(100, tip_rate=0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "acf5afc3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function c_to_f in module __main__:\n", + "\n", + "c_to_f(degrees_c)\n", + "\n" + ] + } + ], + "source": [ + "help(c_to_f)" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "id": "004de762", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " '''Convert degrees from Celsius to Fahrenheit'''\n", + " return ((9 / 5) * degrees_c + 32)" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "0635b9bb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function c_to_f in module __main__:\n", + "\n", + "c_to_f(degrees_c)\n", + " Convert degrees from Celsius to Fahrenheit\n", + "\n" + ] + } + ], + "source": [ + "help(c_to_f)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python-env", + "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.11.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/File-2.ipynb b/File-2.ipynb new file mode 100644 index 000000000..622dfde29 --- /dev/null +++ b/File-2.ipynb @@ -0,0 +1,1163 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "bf9068e5", + "metadata": {}, + "outputs": [], + "source": [ + "# string, text data type\n", + "\n", + "'This is a string'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "099e58f2", + "metadata": {}, + "outputs": [], + "source": [ + "\"This is also a string\"" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "7fe4b6fb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'This\\nis\\ns\\nmultiline\\nstring'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# multiline strings\n", + "\n", + "\"\"\"This\n", + "is\n", + "s\n", + "multiline\n", + "string\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "005854ae", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Let's see if this works\"" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Let\\'s see if this works'" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "aa3bb7a6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'She was fine with apples\\\\oranges'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"She was fine with apples\\\\oranges\"" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "a99bf11f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hellomynameismarte'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"hello\" + \"my\" + \"name\" + \"is\" + \"marte\"" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "070647fe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hahaha'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"ha\" *3" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "0475ce8a", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "can only concatenate str (not \"int\") to str", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[6]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[33;43m\"\u001b[39;49m\u001b[33;43mThe year is\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m2020\u001b[39;49m\n", + "\u001b[31mTypeError\u001b[39m: can only concatenate str (not \"int\") to str" + ] + } + ], + "source": [ + "\"The year is\" + 2020" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "0441577e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The year is 2020'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"The year is \" + \"2020\"" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "e5ae06f3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"apple\" == \"Apple\"" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "73027409", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"apple\" == \"apple\"" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "fb994858", + "metadata": {}, + "outputs": [], + "source": [ + "first_name = \"Ada\"\n", + "last_name = \"Lovelace\"" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "3a40315a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Ada'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "2538f933", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Lovelace'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name" + ] + }, + { + "cell_type": "markdown", + "id": "5d1e3e4e", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "b63d6774", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'A'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "4ea47245", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'vel'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[2:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "ca5ded54", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'lace'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[4:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6321a39b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'a'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# slice from the third-to-last character\n", + "\n", + "last_name[-3]" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "95cc5845", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "fish\n" + ] + } + ], + "source": [ + "print(\"fish\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "c3b5f7d9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 fish 2 fish\n" + ] + } + ], + "source": [ + "print(1, \"fish\", 2, \"fish\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "c67d8de9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "93" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(\"We have a very, very, very, very long sentence and need to know how many characters there are\")" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "948f0cdc", + "metadata": {}, + "outputs": [], + "source": [ + "fruit = \"banana\"" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "0d3d1880", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'banana'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruit" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "0185091c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'a', 'a', 'b', 'n', 'n']" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(fruit)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "6e1426c9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I AM NOT YELLING'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# methods\n", + "# function that works only for a specific type of data\n", + "# e.g., string methods work only on strings\n", + "# methods are called differently from other functions\n", + "\n", + "\"I am not yelling\".upper()" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "7afcba17", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"This string is unusual\".count(\"e\")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "99248b45", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"meow\".capitalize" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "1d91e315", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Meow'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"meow\".capitalize()" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "9e446338", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'long_file_name_with_space.csv'" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"long file name with space.csv\".replace(\" \", \"_\")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "ce207032", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# format ()\n", + "\"Ada Lovelace\\'s initials are {}. {}.\".format(first_name[0], last_name[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "a4d2a0fe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Marte Vroom'" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Marte {}\".format(\"Vroom\")" + ] + }, + { + "cell_type": "markdown", + "id": "7d11f411", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "794f1427", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's are A. L.\"" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# f-string\n", + "\n", + "f\"Ada Lovelace\\'s are {first_name[0]}. {last_name[0]}.\"" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "bb8b74a7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "17" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(17.4)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "d3e750b8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(\"18\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "74f60dfc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(int(\"18\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "c8f338ad", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(15.6)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "24565fda", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(15)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "0ec2a9dd", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'hello' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[39]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28mtype\u001b[39m(\u001b[43mhello\u001b[49m)\n", + "\u001b[31mNameError\u001b[39m: name 'hello' is not defined" + ] + } + ], + "source": [ + "type(hello)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "c4bc35ec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(\"hello\")" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "e1a448b3", + "metadata": {}, + "outputs": [], + "source": [ + "age = input(\"How old are you?\")" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "3e7c5ddc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'30'" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "age" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "5ae1ec83", + "metadata": {}, + "outputs": [], + "source": [ + "color = input(\"What is your favorite color?\")" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "e2116b99", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Pink'" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "color" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "8655586a", + "metadata": {}, + "outputs": [], + "source": [ + "age_next_bday = int(age) + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "b91df1eb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "31" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "age_next_bday" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "40a4ec3c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# not\n", + "# negate the truth value of the statement\n", + "\n", + "not True" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "6169aa52", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not False" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "8e02da1a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 == 7 and 6 == 6" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "70b51825", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 == 7 and 7 == 6" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "8eca81e8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 == 7 or 6 == 6" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "1f3b371b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 == 6 or 6 == 7" + ] + }, + { + "cell_type": "markdown", + "id": "96b332e7", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "d127cf1c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "7 == 7 or 6 == 7" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "id": "81dd08dd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century.\n" + ] + } + ], + "source": [ + "year = 2000\n", + "\n", + "if year >= 2000:\n", + " print(\"We are in the 21st century.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "0527fc06", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are not in the 21st century.\n" + ] + } + ], + "source": [ + "year = 1999\n", + "\n", + "if year >= 2000:\n", + " print(\"We are in the 21st century.\")\n", + "else:\n", + " print(\"We are not in the 21st century.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "5c1d20aa", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 19th century.\n" + ] + } + ], + "source": [ + "year = 1899\n", + "\n", + "if year >= 2000:\n", + " print(\"We are in the 21st century.\")\n", + "elif year >= 1900:\n", + " print (\"We are in the 20th century.\")\n", + "elif year >= 1800:\n", + " print(\"We are in the 19th century.\")\n", + "else:\n", + " print(\"We are way back in time!\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ac6e538c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a9a41f77", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python-env", + "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.11.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/assignment-1.ipynb b/assignment-1.ipynb new file mode 100644 index 000000000..b797ab919 --- /dev/null +++ b/assignment-1.ipynb @@ -0,0 +1,201 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "d516efe7", + "metadata": {}, + "outputs": [], + "source": [ + "def anagram_checker(word_a, word_b):\n", + " # Use sorted() to sort the letters in word_a and word_b\n", + " # Converts word_a and word_b into lists to check if words are anagrams of each other\n", + " # E.g., both silent and listen become [\"e\", \"i\", \"l\", \"n\", \"s\", \"t\"]\n", + " # E.g., both night and thing become [\"g\", \"h\", \"i\", \"n\", \"t\"]\n", + " # Assume that uppercase letters are the same as if it was a lowercase character\n", + " # Use .lower() to convert word_a and word_b to lowercase\n", + " # E.g., Silent becomes silent\n", + " # E.g., Listen becomes listen\n", + " # E.g., Night becomes night\n", + " # E.g., Thing becomes thing\n", + " if sorted(word_a.lower()) == sorted(word_b.lower()):\n", + " return True # Returns true if word_a and word_b are an anagram of each other\n", + " else:\n", + " return False # Returns false if word_a and word_b are not anagrams of each other" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "id": "be2d4784", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"listen\") # True" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "f1b2f5a9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"Night\") # False" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "38e8193b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"night\", \"Thing\") # True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f333b795", + "metadata": {}, + "outputs": [], + "source": [ + "def anagram_checker(word_a, word_b, is_case_sensitive):\n", + " # Adding a boolean to take into account case sensitivity\n", + " # Only converts word_a and word_b to lowercase when is_case_sensitive == False\n", + " if is_case_sensitive == False:\n", + " word_a = word_a.lower() # Makes word_a lowercase only if is_case_sensitive == False\n", + " word_b = word_b.lower() # Makes word_b lowercase only if is_case_sensitive == False\n", + " \n", + " # Add this line to the original code as below\n", + " # Remove .lower() after word_a and word_b from original code\n", + " # If is_case_sensitive == True, this affects the list\n", + " # E.g., Silent becomes [\"e\", \"i\", \"l\", \"n\", \"S\", \"t\"]\n", + " # Note how only S is uppercase\n", + " # If is_case_sensitive == False, the list won't contain uppercase letters\n", + " if sorted(word_a) == sorted(word_b):\n", + " return True\n", + " else:\n", + " return False" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "aa9eadf7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"listen\", False)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "07caa3e4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"listen\", True)" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "32a0f68b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"Listen\", True)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python-env", + "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.11.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From eb2ed608e12efb5cf3f4f74c5876c6f310a5fa3b Mon Sep 17 00:00:00 2001 From: "Marte M. Vroom" Date: Sun, 22 Mar 2026 18:01:39 -0400 Subject: [PATCH 2/2] Assignment 2 submission --- 02_activities/assignments/assignment_2.ipynb | 181 +++++++++++++++++-- 1 file changed, 164 insertions(+), 17 deletions(-) diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index 1ae6fe242..f0102fd51 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -76,7 +76,134 @@ "metadata": { "id": "n0m48JsS-nMC" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0\n", + "\n", + "0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1\n", + "\n", + "0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1\n", + "\n", + "0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1\n", + "\n", + "0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1\n", + "\n", + "0,0,1,2,2,4,2,1,6,4,7,6,6,9,9,15,4,16,18,12,12,5,18,9,5,3,10,3,12,7,8,4,7,3,5,4,4,3,2,1\n", + "\n", + "0,0,2,2,4,2,2,5,5,8,6,5,11,9,4,13,5,12,10,6,9,17,15,8,9,3,13,7,8,2,8,8,4,2,3,5,4,1,1,1\n", + "\n", + "0,0,1,2,3,1,2,3,5,3,7,8,8,5,10,9,15,11,18,19,20,8,5,13,15,10,6,10,6,7,4,9,3,5,2,5,3,2,2,1\n", + "\n", + "0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0\n", + "\n", + "0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0\n", + "\n", + "0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1\n", + "\n", + "0,1,0,0,3,4,2,7,8,5,2,8,11,5,5,8,14,11,6,11,9,16,18,6,12,5,4,3,5,7,8,3,5,4,5,5,4,0,1,1\n", + "\n", + "0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1\n", + "\n", + "0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0\n", + "\n", + "0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0\n", + "\n", + "0,1,1,0,1,2,4,3,6,4,7,5,5,7,5,10,7,8,18,17,9,8,12,11,11,11,14,6,11,2,10,9,5,6,5,3,4,2,2,0\n", + "\n", + "0,0,0,0,2,3,6,5,7,4,3,2,10,7,9,11,12,5,12,9,13,19,14,17,5,13,8,11,5,10,9,8,7,5,3,1,4,0,2,1\n", + "\n", + "0,0,0,1,2,1,4,3,6,7,4,2,12,6,12,4,14,7,8,14,13,19,6,9,12,6,4,13,6,7,2,3,6,5,4,2,3,0,1,0\n", + "\n", + "0,0,2,1,2,5,4,2,7,8,4,7,11,9,8,11,15,17,11,12,7,12,7,6,7,4,13,5,7,6,6,9,2,1,1,2,2,0,1,0\n", + "\n", + "0,1,2,0,1,4,3,2,2,7,3,3,12,13,11,13,6,5,9,16,9,19,16,11,8,9,14,12,11,9,6,6,6,1,1,2,4,3,1,1\n", + "\n", + "0,1,1,3,1,4,4,1,8,2,2,3,12,12,10,15,13,6,5,5,18,19,9,6,11,12,7,6,3,6,3,2,4,3,1,5,4,2,2,0\n", + "\n", + "0,0,2,3,2,3,2,6,3,8,7,4,6,6,9,5,12,12,8,5,12,10,16,7,14,12,5,4,6,9,8,5,6,6,1,4,3,0,2,0\n", + "\n", + "0,0,0,3,4,5,1,7,7,8,2,5,12,4,10,14,5,5,17,13,16,15,13,6,12,9,10,3,3,7,4,4,8,2,6,5,1,0,1,0\n", + "\n", + "0,1,1,1,1,3,3,2,6,3,9,7,8,8,4,13,7,14,11,15,14,13,5,13,7,14,9,10,5,11,5,3,5,1,1,4,4,1,2,0\n", + "\n", + "0,1,1,1,2,3,5,3,6,3,7,10,3,8,12,4,12,9,15,5,17,16,5,10,10,15,7,5,3,11,5,5,6,1,1,1,1,0,2,1\n", + "\n", + "0,0,2,1,3,3,2,7,4,4,3,8,12,9,12,9,5,16,8,17,7,11,14,7,13,11,7,12,12,7,8,5,7,2,2,4,1,1,1,0\n", + "\n", + "0,0,1,2,4,2,2,3,5,7,10,5,5,12,3,13,4,13,7,15,9,12,18,14,16,12,3,11,3,2,7,4,8,2,2,1,3,0,1,1\n", + "\n", + "0,0,1,1,1,5,1,5,2,2,4,10,4,8,14,6,15,6,12,15,15,13,7,17,4,5,11,4,8,7,9,4,5,3,2,5,4,3,2,1\n", + "\n", + "0,0,2,2,3,4,6,3,7,6,4,5,8,4,7,7,6,11,12,19,20,18,9,5,4,7,14,8,4,3,7,7,8,3,5,4,1,3,1,0\n", + "\n", + "0,0,0,1,4,4,6,3,8,6,4,10,12,3,3,6,8,7,17,16,14,15,17,4,14,13,4,4,12,11,6,9,5,5,2,5,2,1,0,1\n", + "\n", + "0,1,1,0,3,2,4,6,8,6,2,3,11,3,14,14,12,8,8,16,13,7,6,9,15,7,6,4,10,8,10,4,2,6,5,5,2,3,2,1\n", + "\n", + "0,0,2,3,3,4,5,3,6,7,10,5,10,13,14,3,8,10,9,9,19,15,15,6,8,8,11,5,5,7,3,6,6,4,5,2,2,3,0,0\n", + "\n", + "0,1,2,2,2,3,6,6,6,7,6,3,11,12,13,15,15,10,14,11,11,8,6,12,10,5,12,7,7,11,5,8,5,2,5,5,2,0,2,1\n", + "\n", + "0,0,2,1,3,5,6,7,5,8,9,3,12,10,12,4,12,9,13,10,10,6,10,11,4,15,13,7,3,4,2,9,7,2,4,2,1,2,1,1\n", + "\n", + "0,0,1,2,4,1,5,5,2,3,4,8,8,12,5,15,9,17,7,19,14,18,12,17,14,4,13,13,8,11,5,6,6,2,3,5,2,1,1,1\n", + "\n", + "0,0,0,3,1,3,6,4,3,4,8,3,4,8,3,11,5,7,10,5,15,9,16,17,16,3,8,9,8,3,3,9,5,1,6,5,4,2,2,0\n", + "\n", + "0,1,2,2,2,5,5,1,4,6,3,6,5,9,6,7,4,7,16,7,16,13,9,16,12,6,7,9,10,3,6,4,5,4,6,3,4,3,2,1\n", + "\n", + "0,1,1,2,3,1,5,1,2,2,5,7,6,6,5,10,6,7,17,13,15,16,17,14,4,4,10,10,10,11,9,9,5,4,4,2,1,0,1,0\n", + "\n", + "0,1,0,3,2,4,1,1,5,9,10,7,12,10,9,15,12,13,13,6,19,9,10,6,13,5,13,6,7,2,5,5,2,1,1,1,1,3,0,1\n", + "\n", + "0,1,1,3,1,1,5,5,3,7,2,2,3,12,4,6,8,15,16,16,15,4,14,5,13,10,7,10,6,3,2,3,6,3,3,5,4,3,2,1\n", + "\n", + "0,0,0,2,2,1,3,4,5,5,6,5,5,12,13,5,7,5,11,15,18,7,9,10,14,12,11,9,10,3,2,9,6,2,2,5,3,0,0,1\n", + "\n", + "0,0,1,3,3,1,2,1,8,9,2,8,10,3,8,6,10,13,11,17,19,6,4,11,6,12,7,5,5,4,4,8,2,6,6,4,2,2,0,0\n", + "\n", + "0,1,1,3,4,5,2,1,3,7,9,6,10,5,8,15,11,12,15,6,12,16,6,4,14,3,12,9,6,11,5,8,5,5,6,1,2,1,2,0\n", + "\n", + "0,0,1,3,1,4,3,6,7,8,5,7,11,3,6,11,6,10,6,19,18,14,6,10,7,9,8,5,8,3,10,2,5,1,5,4,2,1,0,1\n", + "\n", + "0,1,1,3,3,4,4,6,3,4,9,9,7,6,8,15,12,15,6,11,6,18,5,14,15,12,9,8,3,6,10,6,8,7,2,5,4,3,1,1\n", + "\n", + "0,1,2,2,4,3,1,4,8,9,5,10,10,3,4,6,7,11,16,6,14,9,11,10,10,7,10,8,8,4,5,8,4,4,5,2,4,1,1,0\n", + "\n", + "0,0,2,3,4,5,4,6,2,9,7,4,9,10,8,11,16,12,15,17,19,10,18,13,15,11,8,4,7,11,6,7,6,5,1,3,1,0,0,0\n", + "\n", + "0,1,1,3,1,4,6,2,8,2,10,3,11,9,13,15,5,15,6,10,10,5,14,15,12,7,4,5,11,4,6,9,5,6,1,1,2,1,2,1\n", + "\n", + "0,0,1,3,2,5,1,2,7,6,6,3,12,9,4,14,4,6,12,9,12,7,11,7,16,8,13,6,7,6,10,7,6,3,1,5,4,3,0,0\n", + "\n", + "0,0,1,2,3,4,5,7,5,4,10,5,12,12,5,4,7,9,18,16,16,10,15,15,10,4,3,7,5,9,4,6,2,4,1,4,2,2,2,1\n", + "\n", + "0,1,2,1,1,3,5,3,6,3,10,10,11,10,13,10,13,6,6,14,5,4,5,5,9,4,12,7,7,4,7,9,3,3,6,3,4,1,2,0\n", + "\n", + "0,1,2,2,3,5,2,4,5,6,8,3,5,4,3,15,15,12,16,7,20,15,12,8,9,6,12,5,8,3,8,5,4,1,3,2,1,3,1,0\n", + "\n", + "0,0,0,2,4,4,5,3,3,3,10,4,4,4,14,11,15,13,10,14,11,17,9,11,11,7,10,12,10,10,10,8,7,5,2,2,4,1,2,1\n", + "\n", + "0,0,2,1,1,4,4,7,2,9,4,10,12,7,6,6,11,12,9,15,15,6,6,13,5,12,9,6,4,7,7,6,5,4,1,4,2,2,2,1\n", + "\n", + "0,1,2,1,1,4,5,4,4,5,9,7,10,3,13,13,8,9,17,16,16,15,12,13,5,12,10,9,11,9,4,5,5,2,2,5,1,0,0,1\n", + "\n", + "0,0,1,3,2,3,6,4,5,7,2,4,11,11,3,8,8,16,5,13,16,5,8,8,6,9,10,10,9,3,3,5,3,5,4,5,3,3,0,1\n", + "\n", + "0,1,1,2,2,5,1,7,4,2,5,5,4,6,6,4,16,11,14,16,14,14,8,17,4,14,13,7,6,3,7,7,5,6,3,4,2,2,1,1\n", + "\n", + "0,1,1,1,4,1,6,4,6,3,6,5,6,4,14,13,13,9,12,19,9,10,15,10,9,10,10,7,5,6,8,6,6,4,3,5,2,1,1,1\n", + "\n", + "0,0,0,1,4,5,6,3,8,7,9,10,8,6,5,12,15,5,10,5,8,13,18,17,14,9,13,4,10,11,10,8,8,6,5,5,2,0,2,0\n", + "\n", + "0,0,1,0,3,2,5,4,8,2,9,3,3,10,12,9,14,11,13,8,6,18,11,9,13,11,8,5,5,2,8,5,3,5,4,1,3,1,1,0\n", + "\n" + ] + } + ], "source": [ "all_paths = [\n", " \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n", @@ -95,8 +222,10 @@ "\n", "with open(all_paths[0], 'r') as f:\n", " # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n", - " \n", - " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" + " lines = f.readlines() # \n", + " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\n", + " for line in lines:\n", + " print(line)" ] }, { @@ -130,7 +259,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "id": "82-bk4CBB1w4" }, @@ -145,13 +274,13 @@ " # Implement the specific operation based on the 'operation' argument\n", " if operation == 'mean':\n", " # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\n", - "\n", + " summary_values = np.mean(data, axis=1)\n", " elif operation == 'max':\n", " # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n", - "\n", + " summary_values = np.max(data, axis=1)\n", " elif operation == 'min':\n", " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n", - "\n", + " summary_values = np.min(data, axis=1)\n", " else:\n", " # If the operation is not one of the expected values, raise an error\n", " raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n", @@ -161,11 +290,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "id": "3TYo0-1SDLrd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60\n" + ] + } + ], "source": [ "# Test it out on the data file we read in and make sure the size is what we expect i.e., 60\n", "# Your output for the first file should be 60\n", @@ -228,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "id": "_svDiRkdIwiT" }, @@ -251,7 +388,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "id": "LEYPM5v4JT0i" }, @@ -261,15 +398,24 @@ "\n", "def detect_problems(file_path):\n", " #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n", - "\n", - " return" + " mean_values = patient_summary(file_path, 'mean') # Get mean inflammation per patient\n", + " has_zero = check_zeros(mean_values) # Check if any of those means are zero\n", + " return has_zero" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ "# Test out your code here\n", "# Your output for the first file should be False\n", @@ -314,7 +460,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "python-env", + "language": "python", "name": "python3" }, "language_info": { @@ -327,7 +474,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" } }, "nbformat": 4,