From 0d7c1d3f0abb5e36095d9d3142d566f3083bf583 Mon Sep 17 00:00:00 2001 From: pim61sit <106397301+pim61sit@users.noreply.github.com> Date: Sat, 10 May 2025 09:15:51 -0400 Subject: [PATCH] Revert "Revert "Assignment1"" --- 01_materials/Untitled-1.ipynb | 3400 ++++++++++++++++++ 02_activities/assignments/assignment_1.ipynb | 104 +- 02_activities/homework/01_data_types.ipynb | 270 +- 3 files changed, 3760 insertions(+), 14 deletions(-) create mode 100644 01_materials/Untitled-1.ipynb diff --git a/01_materials/Untitled-1.ipynb b/01_materials/Untitled-1.ipynb new file mode 100644 index 000000000..6bc593809 --- /dev/null +++ b/01_materials/Untitled-1.ipynb @@ -0,0 +1,3400 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "af82aa1b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello world!\n" + ] + } + ], + "source": [ + "print(\"hello world!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "47fbe8e6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(42)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "37d06920", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "bool" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(True)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "cd32cd73", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abs(-4)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "d39a133f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6666666666666666" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2/3" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "18324ef3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "int(3.99)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "18f0f8bc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7.0" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "float(7)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "797f5b0f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.15" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2.15" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "7f1e1d5a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "type" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(int)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "7c5b3272", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "print(type(round(2/3)))" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "2061bcbc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Type help() for interactive help, or help(object) for help about object." + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "help" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "202ae606", + "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": 37, + "id": "0279d197", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6667" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(2/3, ndigits = 4)" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "eb29f35b", + "metadata": {}, + "outputs": [], + "source": [ + "def round(num):\n", + " return num + 1" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "3a7e291c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "round(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "cf8d0d72", + "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": 2, + "id": "e5fd0057", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "212.0" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7806b621", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.2" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(-11)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "11ac18c0", + "metadata": {}, + "outputs": [], + "source": [ + "freesing_f = c_to_f(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "12301a17", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "32.0" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "freesing_f" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "bd1c95a7", + "metadata": {}, + "outputs": [], + "source": [ + "def divide(dividend, divisor):\n", + " output = dividend /divisor\n", + " return output\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "7babcf5e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "divide(0, 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "912c2ce0", + "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[14], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdivide\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[0;32mIn[8], line 2\u001b[0m, in \u001b[0;36mdivide\u001b[0;34m(dividend, divisor)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mdivide\u001b[39m(dividend, divisor):\n\u001b[0;32m----> 2\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[43mdividend\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43mdivisor\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m output\n", + "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" + ] + } + ], + "source": [ + "divide(2, 0)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "ae546229", + "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": 27, + "id": "16fe1d4a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.65" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calc_sales_tax(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "0c290e03", + "metadata": {}, + "outputs": [], + "source": [ + "def cal_total_bill(price, tax_rate=0.13, tip_rate=0.15):\n", + " tax_amt = price * tax_rate\n", + " tip_amt = price * tip_rate\n", + " total_price = price + tax_amt + tip_amt\n", + " return total_price" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "ff674b7a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "128.0" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cal_total_bill(100)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "2470a937", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "133.0" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cal_total_bill(100, 0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "50bb579c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "131.0" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cal_total_bill(100, tip_rate = 0.18)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "cc1dce40", + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " '''Convert degrees from Celsius to Fahrenheit'''\n", + " degrees_f = (9/5) * degrees_c +32\n", + " return degrees_f" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "25787697", + "metadata": {}, + "outputs": [], + "source": [ + "# String is Python's text data type\n", + "# Sequences of characters, including digits and symbols\n", + "# surrounded by quotation makrs (iether single or double)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "9733d908", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string'" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'This is a string'" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "bf613e7f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'This is also a string'" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"This is also a string\"" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "341e88c5", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "EOL while scanning string literal (844737843.py, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[44], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m \"These quotes do not match'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m EOL while scanning string literal\n" + ] + } + ], + "source": [ + "\"These quotes do not match'" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "79015f05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "And\tor\n" + ] + } + ], + "source": [ + "print('And\\tor')" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "d58eeb6c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "30thy is April \n" + ] + } + ], + "source": [ + "print(\"Today is April \\r30th\")" + ] + }, + { + "cell_type": "markdown", + "id": "460861f7", + "metadata": {}, + "source": [ + "'hello' + 'world'" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "5ce54068", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello world'" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'hello' + ' ' + 'world'" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "ac98c14f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hahaha'" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'ha' * 3" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "42a9e7bc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The year is 2025'" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'The year is' + ' ' + '2025'" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "ce99d9b6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 == 3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'apple' == 'apple''" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Apple' == \"aple\"" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "d31d97ea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'20' == 20" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "id": "caf36a41", + "metadata": {}, + "outputs": [], + "source": [ + "first_name = \"Ada\"\n", + "last_name = \"Lovelace\"" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "021e43a1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'a'" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "9583e605", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'l'" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[4]" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "id": "7a42b1e4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'la'" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[4:6]" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "id": "8f911a8d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Lovel'" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 84, + "id": "78563039", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'velace'" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_name[2:]" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "id": "635787e6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "o a\n" + ] + } + ], + "source": [ + "print(last_name[1], last_name[5])" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "85fb9162", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 fish 2 fish\n" + ] + } + ], + "source": [ + "print(1, 'fish', 2, 'fish')" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "82a510ce", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "21" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len('this is a loooooooong')" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "af65aada", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on built-in function len in module builtins:\n", + "\n", + "len(obj, /)\n", + " Return the number of items in a container.\n", + "\n" + ] + } + ], + "source": [ + "help(len)" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "cbe1b7fe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'I AM NOT YELLING'" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'I am not yelling'.upper()" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "5cee0f33", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'This string is unsuall'.count('e')" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "29d6b65f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'file_name.csv'.endswith('.csv')" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "d8b9e8fa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'file_name_with_spaces.scv'" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'file name with spaces.scv'.replace(' ', '_') " + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "27242c8d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'a', 'a', 'b', 'n', 'n']" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruit = 'banana'\n", + "\n", + "sorted(fruit)" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "id": "651dbe53", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['A', 'a']" + ] + }, + "execution_count": 110, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruit = 'Aa'\n", + "\n", + "sorted(fruit)" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "a465dcca", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace's initials are A. L.\"" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name = 'Ada'\n", + "last_name = \"Lovelace\"\n", + "\n", + "'Ada Lovelace\\'s initials are {}. {}.'.format(first_name[0], last_name[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9702814c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'My favorite seasons are spring and winter'" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'My favorite seasons are {} and {}'.format('spring', 'winter')" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "id": "305907d6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Ada'" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "first_name" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "id": "ecb3c89b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Ada Lovelace 's initial is A\"" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f'Ada Lovelace \\'s initial is {first_name[0]}'" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "id": "2b5baed7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'My favorite fruit and veg are banana and beans, respetively.'" + ] + }, + "execution_count": 124, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fruit = 'banana'\n", + "vegentable = 'beans'\n", + "\n", + "\"My favorite fruit and veg are {} and {}, respetively.\".format(fruit, vegentable)" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "id": "7581c0c3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'My favorite seasons is summer'" + ] + }, + "execution_count": 135, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "season = 'summer'\n", + "f'My favorite seasons is {season}'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "405d40a5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "17" + ] + }, + "execution_count": 137, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# string to integer\n", + "\n", + "# int() function only convert strings that represent whole numbers into integers.\n", + "int('17')" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "id": "db6bf4b5", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: '178.4'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[140], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m178.4\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: '178.4'" + ] + } + ], + "source": [ + "int('178.4')" + ] + }, + { + "cell_type": "code", + "execution_count": 142, + "id": "1226a9b6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "892.0" + ] + }, + "execution_count": 142, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#string to float\n", + "\n", + "float('892')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 145, + "id": "51ef22ce", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'37.5'" + ] + }, + "execution_count": 145, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#float and int into string\n", + "\n", + "str(37.5)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 147, + "id": "c067f187", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'20'" + ] + }, + "execution_count": 147, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(20)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "id": "d5005806", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'2037.5'" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'20' +str(37.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "id": "b91f325a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 152, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(7 == 7.0) and (32> 9)" + ] + }, + { + "cell_type": "code", + "execution_count": 155, + "id": "a97555c9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 155, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "is_summer = True\n", + "is_sunny = True\n", + "is_summer and is_sunny" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "id": "ad81a37b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 156, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "is_winter = \"True\" # string with the value \"True\"\n", + "is_cloudy = True # boolean with the value true\n", + "is_winter and is_cloudy" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "id": "be133dab", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "is_cloudy and is_winter" + ] + }, + { + "cell_type": "code", + "execution_count": 161, + "id": "f56b3e69", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'python'" + ] + }, + "execution_count": 161, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"Python\" and \"python\"" + ] + }, + { + "cell_type": "code", + "execution_count": 163, + "id": "93ce8a26", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 163, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "False and \"non-empty string\"" + ] + }, + { + "cell_type": "code", + "execution_count": 165, + "id": "820a7f13", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 165, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Python' == 'python' or True" + ] + }, + { + "cell_type": "code", + "execution_count": 167, + "id": "faea2bf9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 167, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Python' == 'python'" + ] + }, + { + "cell_type": "code", + "execution_count": 170, + "id": "b27f4f08", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 170, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "not (7 % 2 == 1) or False" + ] + }, + { + "cell_type": "code", + "execution_count": 174, + "id": "cba23edb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'True'" + ] + }, + "execution_count": 174, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "is_winter = \"True\"\n", + "is_cloudy = True\n", + "\n", + "is_winter or is_cloudy" + ] + }, + { + "cell_type": "code", + "execution_count": 177, + "id": "7ce3f2a6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st centry.\n" + ] + } + ], + "source": [ + "year = 2022\n", + "\n", + "if year >= 2000:\n", + " print('We are in the 21st centry.')" + ] + }, + { + "cell_type": "code", + "execution_count": 179, + "id": "9ab1b1e0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are not in the 21st centry.\n" + ] + } + ], + "source": [ + "year = 1999\n", + "if year >= 2000:\n", + " print('We are in the 21st century.')\n", + "else:\n", + " print('We are not in the 21st centry.')" + ] + }, + { + "cell_type": "code", + "execution_count": 187, + "id": "4fcf18b7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "We are in the 21st century.\n" + ] + } + ], + "source": [ + "year = 2025\n", + "\n", + "if year >= 2000:\n", + " print('We are in the 21st century.')\n", + "elif year >= 1900:\n", + " print('We are in the 20th centry.')\n", + "elif year >= 1800:\n", + " print('We are in the 19st centry.')\n", + "else:\n", + " print('We have gone way back in time')" + ] + }, + { + "cell_type": "code", + "execution_count": 193, + "id": "95153d1a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Weekend\n" + ] + } + ], + "source": [ + "day_of_week = \"Saturday\"\n", + "\n", + "if day_of_week == 'Saturday' or day_of_week == 'Sunday':\n", + " print('Weekend')\n", + "else: \n", + " print('Weekday')" + ] + }, + { + "cell_type": "code", + "execution_count": 221, + "id": "cae5eeee", + "metadata": {}, + "outputs": [], + "source": [ + "def eye_exam_covered(age, qualifying_condition, time_since_last_exam):\n", + " '''qualifying_condition is True/False on whether you have an eligible medical condition'''\n", + " if age <= 19:\n", + " if time_since_last_exam >= 12:\n", + " return \"you are eligible for 1 major eye exam and any minor assessments.\"\n", + " else:\n", + " return \"it hasn't been 12 months since your last major eye exam.\"\n", + " elif 20 <= age <= 64:\n", + " if qualifying_condition:\n", + " if time_since_last_exam >= 12:\n", + " return \"you are eligible for 1 major eye exam & 2 follow-up minor assessments\"\n", + " else:\n", + " return \"it hasn't been 12 months since your last major eye exam\"\n", + " else:\n", + " return \"you do not have an eligible medical condition\"\n", + " elif age <= 65:\n", + " if time_since_last_exam >= 18:\n", + " return \"you are eligible for 1 major eye exam and 2 follow-up minor assessments\"\n", + " else:\n", + " return \"it hasn't been 18 months since your last major eye exam\"\n", + " else:\n", + " return \"invalid age input\"" + ] + }, + { + "cell_type": "code", + "execution_count": 223, + "id": "a32d3a8d", + "metadata": {}, + "outputs": [], + "source": [ + "def eye_exam_covered(age, qualifying_condition, time_since_last_exam):\n", + " '''qualifying_condition is True/False on whether you have an eligible medical condition'''\n", + " if age <= 19:\n", + " if time_since_last_exam >= 12:\n", + " return \"you are eligible for 1 major eye exam and any minor assessments.\"\n", + " else:\n", + " return \"it hasn't been 12 months since your last major eye exam.\"\n", + " elif 20 <= age <= 64:\n", + " if qualifying_condition:\n", + " if time_since_last_exam >= 12:\n", + " return \"you are eligible for 1 major eye exam & 2 follow-up minor assessments\"\n", + " else:\n", + " return \"it hasn't been 12 months since your last major eye exam\"\n", + " else:\n", + " return \"you do not have an eligible medical condition\"\n", + " elif age <= 65:\n", + " if time_since_last_exam >= 18:\n", + " return \"you are eligible for 1 major eye exam and 2 follow-up minor assessments\"\n", + " else:\n", + " return \"it hasn't been 18 months since your last major eye exam\"\n", + " else:\n", + " return \"invalid age input\"" + ] + }, + { + "cell_type": "code", + "execution_count": 224, + "id": "14e41504", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'you are eligible for 1 major eye exam & 2 follow-up minor assessments'" + ] + }, + "execution_count": 224, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(27, True, 15)" + ] + }, + { + "cell_type": "code", + "execution_count": 226, + "id": "0588e46e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'you do not have an eligible medical condition'" + ] + }, + "execution_count": 226, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "eye_exam_covered(20, False, 11)" + ] + }, + { + "cell_type": "code", + "execution_count": 231, + "id": "955d7e24", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u']" + ] + }, + "execution_count": 231, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vowels = ['a', 'e', 'i', 'o', 'u']\n", + "vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 233, + "id": "65c93f2f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 233, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "emply_list = []\n", + "type(emply_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 235, + "id": "aa846cee", + "metadata": {}, + "outputs": [], + "source": [ + "emply_list2 = list()" + ] + }, + { + "cell_type": "code", + "execution_count": 237, + "id": "6b517443", + "metadata": {}, + "outputs": [], + "source": [ + "scores = [90, 80, 70, 70]\n", + "grades = ['K', 1, 2, 3, 4, 5]\n", + "summary_functions = [len, sum, max, min]" + ] + }, + { + "cell_type": "code", + "execution_count": 240, + "id": "25d7d4b3", + "metadata": {}, + "outputs": [], + "source": [ + "mystery_solvers = [\n", + " ['Sherlock', 'Watson'],\n", + " ['Scooby', 'Shaggy', 'Fred'],\n", + " 'Nancy'\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": 244, + "id": "02d11b42", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'K'" + ] + }, + "execution_count": 244, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades [0]" + ] + }, + { + "cell_type": "code", + "execution_count": 247, + "id": "1b0a03a8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4]" + ] + }, + "execution_count": 247, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades [1:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 250, + "id": "d7828c4e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 3, 4, 5]" + ] + }, + "execution_count": 250, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades [-4:]" + ] + }, + { + "cell_type": "code", + "execution_count": 252, + "id": "63f964ac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5]" + ] + }, + "execution_count": 252, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grades [1:6]" + ] + }, + { + "cell_type": "code", + "execution_count": 254, + "id": "026d4380", + "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[254], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mgrades\u001b[49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[0;31mIndexError\u001b[0m: list index out of range" + ] + } + ], + "source": [ + "grades [10]" + ] + }, + { + "cell_type": "code", + "execution_count": 256, + "id": "d392332d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 256, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'Hiro' in 'James loves coffee'" + ] + }, + { + "cell_type": "code", + "execution_count": 258, + "id": "9f7bfb12", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'e', 'i', 'o', 'u']" + ] + }, + "execution_count": 258, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 262, + "id": "806fbd36", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 262, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'K' in vowels" + ] + }, + { + "cell_type": "code", + "execution_count": 264, + "id": "7399a4ae", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['Sherlock', 'Watson'], ['Scooby', 'Shaggy', 'Fred'], 'Nancy']" + ] + }, + "execution_count": 264, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mystery_solvers" + ] + }, + { + "cell_type": "code", + "execution_count": 266, + "id": "09c1975c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Sherlock', 'Watson']" + ] + }, + "execution_count": 266, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mystery_solvers[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 269, + "id": "048e2528", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Sherlock'" + ] + }, + "execution_count": 269, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mystery_solvers[0][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 272, + "id": "0742e7d2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 272, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vowels.index('e')" + ] + }, + { + "cell_type": "code", + "execution_count": 275, + "id": "78179af0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 37, 49]" + ] + }, + "execution_count": 275, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares = [ 1, 4, 9, 16, 25, 37, 49]\n", + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 277, + "id": "83b71536", + "metadata": {}, + "outputs": [], + "source": [ + "julia = 'cheese sandwich'\n", + "Hiro = julia\n" + ] + }, + { + "cell_type": "code", + "execution_count": 279, + "id": "e3d9f55a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 279, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia" + ] + }, + { + "cell_type": "code", + "execution_count": 281, + "id": "92616f24", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 281, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Hiro" + ] + }, + { + "cell_type": "code", + "execution_count": 283, + "id": "4abdb36d", + "metadata": {}, + "outputs": [], + "source": [ + "julia = 'ham sandwich'" + ] + }, + { + "cell_type": "code", + "execution_count": 285, + "id": "e91899b7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'ham sandwich'" + ] + }, + "execution_count": 285, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia" + ] + }, + { + "cell_type": "code", + "execution_count": 287, + "id": "5edaaa17", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'cheese sandwich'" + ] + }, + "execution_count": 287, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Hiro" + ] + }, + { + "cell_type": "code", + "execution_count": 289, + "id": "b55d9fca", + "metadata": {}, + "outputs": [], + "source": [ + "julia_list = ['bread', 'cheese', 'bread']" + ] + }, + { + "cell_type": "code", + "execution_count": 291, + "id": "5691500c", + "metadata": {}, + "outputs": [], + "source": [ + "Hiro_list = julia_list" + ] + }, + { + "cell_type": "code", + "execution_count": 293, + "id": "76eb8ae5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'cheese', 'bread']" + ] + }, + "execution_count": 293, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia_list" + ] + }, + { + "cell_type": "code", + "execution_count": 295, + "id": "5bc0e243", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'cheese', 'bread']" + ] + }, + "execution_count": 295, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Hiro_list" + ] + }, + { + "cell_type": "code", + "execution_count": 297, + "id": "6aa2c07b", + "metadata": {}, + "outputs": [], + "source": [ + "julia_list[1] = 'ham'" + ] + }, + { + "cell_type": "code", + "execution_count": 299, + "id": "268062e3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'ham', 'bread']" + ] + }, + "execution_count": 299, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "julia_list" + ] + }, + { + "cell_type": "code", + "execution_count": 301, + "id": "a932c703", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['bread', 'ham', 'bread']" + ] + }, + "execution_count": 301, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Hiro_list" + ] + }, + { + "cell_type": "code", + "execution_count": 303, + "id": "4f7cea9a", + "metadata": {}, + "outputs": [], + "source": [ + "a = 1\n", + "b = a " + ] + }, + { + "cell_type": "code", + "execution_count": 305, + "id": "cac6a63d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 305, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 306, + "id": "af5cc34f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 306, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 308, + "id": "f0cf8dbb", + "metadata": {}, + "outputs": [], + "source": [ + "a = 2" + ] + }, + { + "cell_type": "code", + "execution_count": 310, + "id": "b0ef6ed3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 310, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a\n" + ] + }, + { + "cell_type": "code", + "execution_count": 318, + "id": "f2b38da2", + "metadata": {}, + "outputs": [], + "source": [ + "a = [1,2]" + ] + }, + { + "cell_type": "code", + "execution_count": 319, + "id": "7c0d85f5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2]" + ] + }, + "execution_count": 319, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 320, + "id": "b505a449", + "metadata": {}, + "outputs": [], + "source": [ + "a = b" + ] + }, + { + "cell_type": "code", + "execution_count": 322, + "id": "fb22de52", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 322, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b " + ] + }, + { + "cell_type": "code", + "execution_count": 324, + "id": "8d55fa94", + "metadata": {}, + "outputs": [], + "source": [ + "combo = ['burger', 'fries', 'drink']\n", + "kid_meal = list(combo)" + ] + }, + { + "cell_type": "code", + "execution_count": 325, + "id": "31d90146", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['burger', 'fries', 'drink']" + ] + }, + "execution_count": 325, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kid_meal" + ] + }, + { + "cell_type": "code", + "execution_count": 327, + "id": "42d9c93c", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "combo[0] = 'veggie burger'" + ] + }, + { + "cell_type": "code", + "execution_count": 329, + "id": "ffc1afb9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['veggie burger', 'fries', 'drink']" + ] + }, + "execution_count": 329, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "combo" + ] + }, + { + "cell_type": "code", + "execution_count": 331, + "id": "392c2513", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['burger', 'fries', 'drink']" + ] + }, + "execution_count": 331, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kid_meal" + ] + }, + { + "cell_type": "code", + "execution_count": 332, + "id": "d2ad8b90", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 37, 49]" + ] + }, + "execution_count": 332, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares" + ] + }, + { + "cell_type": "code", + "execution_count": 334, + "id": "c48137a7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 334, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(perfect_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 336, + "id": "526f1fa6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "49" + ] + }, + "execution_count": 336, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max(perfect_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 338, + "id": "fc820673", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "141" + ] + }, + "execution_count": 338, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sum(perfect_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 341, + "id": "7ca8833c", + "metadata": {}, + "outputs": [], + "source": [ + "letters = ['a', 'b', 'c']\n", + "numbers = [1, 2, 3]\n", + "characters = letters + numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 343, + "id": "d88f031b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'b', 'c', 1, 2, 3]" + ] + }, + "execution_count": 343, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "characters" + ] + }, + { + "cell_type": "code", + "execution_count": 344, + "id": "4f35fe95", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a', 'b', 'c', 'a', 'b', 'c']" + ] + }, + "execution_count": 344, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "letters * 2" + ] + }, + { + "cell_type": "code", + "execution_count": 346, + "id": "0fe4e94a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 1, 2, 3]" + ] + }, + "execution_count": 346, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "numbers * 2" + ] + }, + { + "cell_type": "code", + "execution_count": 348, + "id": "3ec4f2ee", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 37, 49, 1, 4, 9, 16, 25, 37, 49]" + ] + }, + "execution_count": 348, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "perfect_squares * 2" + ] + }, + { + "cell_type": "code", + "execution_count": 350, + "id": "5a880c12", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'violet']" + ] + }, + { + "cell_type": "code", + "execution_count": 352, + "id": "68090ccc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red', 'orange', 'yellow', 'green', 'blue', 'violet', 'purple', 'purple']" + ] + }, + "execution_count": 352, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#append will add a single element to the end of a list.\n", + "\n", + "rainbow.append('purple')\n", + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 356, + "id": "007c1148", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " 'purple',\n", + " ['purple'],\n", + " ['purple']]" + ] + }, + "execution_count": 356, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow.append(['purple'])\n", + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 358, + "id": "b8e88fb7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " 'purple',\n", + " ['purple'],\n", + " ['purple'],\n", + " ['magenta', 'pink'],\n", + " ['magenta', 'pink']]" + ] + }, + "execution_count": 358, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# extend used to add elements from an interable to the end of a list\n", + "#this will unpack the elements of an iterable and add them on by one to the end of the original list.\n", + "\n", + "rainbow.append(['magenta', 'pink'])\n", + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 361, + "id": "a9557dd5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " 'purple',\n", + " ['purple'],\n", + " ['purple'],\n", + " ['magenta', 'pink'],\n", + " ['magenta', 'pink'],\n", + " 'magenta',\n", + " 'pink',\n", + " 'magenta',\n", + " 'pink']" + ] + }, + "execution_count": 361, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow.extend(['magenta', 'pink'])\n", + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 363, + "id": "4fd6d9ac", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'blue',\n", + " 'violet',\n", + " 'purple',\n", + " 'purple',\n", + " ['purple'],\n", + " ['purple'],\n", + " ['magenta', 'pink'],\n", + " ['magenta', 'pink'],\n", + " 'magenta',\n", + " 'pink',\n", + " 'magenta',\n", + " 'pink',\n", + " 'p',\n", + " 'a',\n", + " 'l',\n", + " 'e',\n", + " ' ',\n", + " 'p',\n", + " 'i',\n", + " 'n',\n", + " 'k',\n", + " 'p',\n", + " 'a',\n", + " 'l',\n", + " 'e',\n", + " ' ',\n", + " 'p',\n", + " 'i',\n", + " 'n',\n", + " 'k']" + ] + }, + "execution_count": 363, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow.extend('pale pink')\n", + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 365, + "id": "3b433d6c", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.insert(6, 'indigo')" + ] + }, + { + "cell_type": "code", + "execution_count": 367, + "id": "028afbc4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'blue',\n", + " 'violet',\n", + " 'indigo',\n", + " 'purple',\n", + " 'purple',\n", + " ['purple'],\n", + " ['purple'],\n", + " ['magenta', 'pink'],\n", + " ['magenta', 'pink'],\n", + " 'magenta',\n", + " 'pink',\n", + " 'magenta',\n", + " 'pink',\n", + " 'p',\n", + " 'a',\n", + " 'l',\n", + " 'e',\n", + " ' ',\n", + " 'p',\n", + " 'i',\n", + " 'n',\n", + " 'k',\n", + " 'p',\n", + " 'a',\n", + " 'l',\n", + " 'e',\n", + " ' ',\n", + " 'p',\n", + " 'i',\n", + " 'n',\n", + " 'k']" + ] + }, + "execution_count": 367, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 369, + "id": "3344fa5c", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.remove('p')" + ] + }, + { + "cell_type": "code", + "execution_count": 371, + "id": "e7520e50", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['red',\n", + " 'orange',\n", + " 'yellow',\n", + " 'green',\n", + " 'blue',\n", + " 'violet',\n", + " 'indigo',\n", + " 'purple',\n", + " 'purple',\n", + " ['purple'],\n", + " ['purple'],\n", + " ['magenta', 'pink'],\n", + " ['magenta', 'pink'],\n", + " 'magenta',\n", + " 'pink',\n", + " 'magenta',\n", + " 'pink',\n", + " 'a',\n", + " 'l',\n", + " 'e',\n", + " ' ',\n", + " 'i',\n", + " 'n',\n", + " 'k',\n", + " 'p',\n", + " 'a',\n", + " 'l',\n", + " 'e',\n", + " ' ',\n", + " 'p',\n", + " 'i',\n", + " 'n',\n", + " 'k']" + ] + }, + "execution_count": 371, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 372, + "id": "258b2a9c", + "metadata": {}, + "outputs": [], + "source": [ + "del rainbow[-13:]" + ] + }, + { + "cell_type": "code", + "execution_count": 374, + "id": "be9ee1a3", + "metadata": {}, + "outputs": [], + "source": [ + "rainbow.clear()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5e96a77e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 376, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": 377, + "id": "cd8baaeb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 377, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rainbow" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "91fb4a18", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n" + ] + } + ], + "source": [ + "# sort () method\n", + "fruits = ['pineapple', 'apple', 'kiwi', 'banana']\n", + "print(fruits.sort())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56d3fdec", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['apple', 'banana', 'kiwi', 'pineapple']\n" + ] + } + ], + "source": [ + "print(fruits) # method sorts/modifies the original list in place" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f333d0f2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['bell pepper', 'cabbage', 'celery', 'onion', 'potatos']\n" + ] + } + ], + "source": [ + "# sort () function\n", + "\n", + "veggies = ['potatos', 'celery', 'cabbage', 'bell pepper', 'onion']\n", + "print(sorted(veggies)) # function returns sorted list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "913d1f8c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['potatos', 'celery', 'cabbage', 'bell pepper', 'onion']\n" + ] + } + ], + "source": [ + "print(veggies) # function does not modify the original list." + ] + }, + { + "cell_type": "code", + "execution_count": 384, + "id": "6d807442", + "metadata": {}, + "outputs": [], + "source": [ + "# by dafault ints and foats will be sorted in ascending order.\n", + "# strings sorted alphabetically based on the Unicode code point value of each character\n", + "# 'A' -> 65\n", + "# 'a' -> 97" + ] + }, + { + "cell_type": "code", + "execution_count": 385, + "id": "02a21ae1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Apple', 'Bacon', 'anger', 'bun']" + ] + }, + "execution_count": 385, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(['Bacon', 'bun', 'Apple', 'anger'])" + ] + }, + { + "cell_type": "code", + "execution_count": 387, + "id": "b085c036", + "metadata": {}, + "outputs": [], + "source": [ + "def last_letter(text):\n", + " return text[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 389, + "id": "7efd80ef", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'o'" + ] + }, + "execution_count": 389, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "last_letter('hiro')" + ] + }, + { + "cell_type": "code", + "execution_count": 390, + "id": "75e14b65", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['cabbage', 'onion', 'bell pepper', 'potatos', 'celery']" + ] + }, + "execution_count": 390, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sorted(veggies, key=last_letter)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2151c875", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "dsi_participant", + "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.9.18" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index bd82b6b8b..86cc9528c 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,24 +56,54 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", - "\n", + " word_a = word_a.lower() \n", + " word_b = word_b.lower()\n", + " return sorted(word_a) == sorted(word_b)\n", + " \n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "# For testing purposes, we will write our code in the function\n", + "def anagram_checker(word_a, word_b):\n", + " word_a = word_a.upper() \n", + " word_b = word_b.upper()\n", + " return sorted(word_a) == sorted(word_b)\n", + "\n", "anagram_checker(\"Silent\", \"Night\")" ] }, @@ -81,8 +111,24 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "def anagram_checker(word_a, word_b):\n", + " word_a = word_a.lower() \n", + " word_b = word_b.lower()\n", + " return sorted(word_a) == sorted(word_b)\n", + "\n", "anagram_checker(\"night\", \"Thing\")" ] }, @@ -99,21 +145,53 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower() \n", + " word_b = word_b.lower()\n", + " return sorted(word_a) == sorted(word_b)\n", "\n", "# Run your code to check using the words below:\n", + "\n", "anagram_checker(\"Silent\", \"listen\", False) # True" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "def anagram_checker(word_a, word_b, is_case_sensitive):\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower() \n", + " word_b = word_b.lower()\n", + " return sorted(word_a) == sorted(word_b)\n", + "\n", "anagram_checker(\"Silent\", \"Listen\", True) # False" ] }, @@ -130,7 +208,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -144,7 +222,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.18" } }, "nbformat": 4, diff --git a/02_activities/homework/01_data_types.ipynb b/02_activities/homework/01_data_types.ipynb index f60123d4b..a1031e259 100644 --- a/02_activities/homework/01_data_types.ipynb +++ b/02_activities/homework/01_data_types.ipynb @@ -1 +1,269 @@ -{"cells":[{"cell_type":"markdown","metadata":{"id":"jNAI57ELh-I8"},"source":["# Getting Started: Python Fundamentals\n","## Practice Problems"]},{"cell_type":"markdown","metadata":{"id":"5xeRB_0jiT5n"},"source":["### 1. What types are involved in the following expressions? What data type will each expression evaluate to?\n","\n","`8 * 2.5`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":158,"status":"ok","timestamp":1667929890889,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"C6c48sSBOUeE","outputId":"3628ffce-faf6-4d23-daff-5e09edf76541"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"4eICUfHi_Z-K"},"source":["`9 / 2`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":43,"status":"ok","timestamp":1667929891449,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"QVdbNoA2OiQ_","outputId":"ab9f4fac-b1cc-4afc-cc54-10592b92abb1"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"DhrJoWbj_cNe"},"source":["`9 // -2`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":39,"status":"ok","timestamp":1667929891450,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"cSsGq3r0Opx6","outputId":"13df11ef-d136-4a42-884e-be1e369aae52"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"lW4UnVfw_eYy"},"source":["`1.5 * 2 >= 7 - 3`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":34,"status":"ok","timestamp":1667929891452,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"54N6gcNPOylS","outputId":"938208fc-c4c3-4e58-dd18-b50d3acc84d8"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"5T-ytiTw-KvJ"},"source":["### 2. In which order will the expressions be evaluated.\n","\n","`6 * 3 + 7 * 4`\n","\n","\n","
\n"," Answer\n","\n"," `*` > `*` > `+` \n","
\n","\n","\n","`5 - 2 * 3 ** 4`\n","\n","
\n"," Answer\n","\n"," `**` > `*` > `-`\n","
\n","\n","`(5 - 2) * 3 ** 4`\n","\n","
\n"," Answer\n","\n"," `(-)` > `**` > `*` \n","
\n","\n","`5 + 2 >= 3 * 4`\n","\n","
\n"," Answer\n","\n"," `*` > `+` > `>=`\n","
"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMhUBNX+UP2C+YDtVSxQKBK","collapsed_sections":[],"provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "jNAI57ELh-I8" + }, + "source": [ + "# Getting Started: Python Fundamentals\n", + "## Practice Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5xeRB_0jiT5n" + }, + "source": [ + "### 1. What types are involved in the following expressions? What data type will each expression evaluate to?\n", + "\n", + "`8 * 2.5`" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 158, + "status": "ok", + "timestamp": 1667929890889, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "C6c48sSBOUeE", + "outputId": "3628ffce-faf6-4d23-daff-5e09edf76541" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "16" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here\n", + "8*2" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4eICUfHi_Z-K" + }, + "source": [ + "`9 / 2`" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 43, + "status": "ok", + "timestamp": 1667929891449, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "QVdbNoA2OiQ_", + "outputId": "ab9f4fac-b1cc-4afc-cc54-10592b92abb1" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "4.5" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here\n", + "9/2" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DhrJoWbj_cNe" + }, + "source": [ + "`9 // -2`" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 39, + "status": "ok", + "timestamp": 1667929891450, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "cSsGq3r0Opx6", + "outputId": "13df11ef-d136-4a42-884e-be1e369aae52" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "-5" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here\n", + "9//-2" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "lW4UnVfw_eYy" + }, + "source": [ + "`1.5 * 2 >= 7 - 3`" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 34, + "status": "ok", + "timestamp": 1667929891452, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "54N6gcNPOylS", + "outputId": "938208fc-c4c3-4e58-dd18-b50d3acc84d8" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here\n", + "1.5 * 2 >= 7-3" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5T-ytiTw-KvJ" + }, + "source": [ + "### 2. In which order will the expressions be evaluated.\n", + "\n", + "`6 * 3 + 7 * 4`\n", + "\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `*` > `*` > `+` \n", + "
\n", + "\n", + "\n", + "`5 - 2 * 3 ** 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `**` > `*` > `-`\n", + "
\n", + "\n", + "`(5 - 2) * 3 ** 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `(-)` > `**` > `*` \n", + "
\n", + "\n", + "`5 + 2 >= 3 * 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `*` > `+` > `>=`\n", + "
" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMhUBNX+UP2C+YDtVSxQKBK", + "collapsed_sections": [], + "provenance": [] + }, + "kernelspec": { + "display_name": "dsi_participant", + "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.9.18" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}