diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 00000000..b8086ace
Binary files /dev/null and b/.DS_Store differ
diff --git a/.ipynb_checkpoints/1.1_data_structures-checkpoint.ipynb b/.ipynb_checkpoints/1.1_data_structures-checkpoint.ipynb
new file mode 100644
index 00000000..d6165010
--- /dev/null
+++ b/.ipynb_checkpoints/1.1_data_structures-checkpoint.ipynb
@@ -0,0 +1,2123 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "103c8f9f",
+ "metadata": {
+ "toc": true
+ },
+ "source": [
+ "
Table of Contents
\n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "181048e2",
+ "metadata": {},
+ "source": [
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "813ac079-1796-4acf-9bd9-90702cb870d8",
+ "metadata": {
+ "tags": []
+ },
+ "source": [
+ "# Prework review - Data types and Data structures"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "be6c0098-5bdf-44d5-be00-4092f33415eb",
+ "metadata": {},
+ "source": [
+ "## Data Types "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3e17c061-b60d-4476-b16c-1c76c0554040",
+ "metadata": {},
+ "source": [
+ "Let's review the fundamental data types in Python:\n",
+ "\n",
+ "- Integer: Represents whole numbers (e.g., 10, 3, -5, 0).\n",
+ "- Float: Represents decimal numbers (e.g., 20.2, 100.2403, -5.50).\n",
+ "- String: Represents text or a group of characters (e.g., \"Hello, World!\", \"Python\").\n",
+ "- Boolean: Represents either True or False.\n",
+ "\n",
+ "The `type()` function is used to check the data type of a variable."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f2b61dac-ee02-4d06-a93a-16f6b2928262",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x = 10 # integer\n",
+ "print(x)\n",
+ "print(type(x))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a31bbdf4-bc3b-4e2b-827b-cb71d0a47c4f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "y = 20.5 # float\n",
+ "print(y) \n",
+ "print(type(y))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "dae8a3de-c7ac-426a-9666-1fea9c5c823f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "z = \"hello\" # String can be encapsulated in single quotes or double quotes.\n",
+ "print(z)\n",
+ "print(type(z))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6553fd5f-144c-4e4a-b699-5b7e2512556d",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "b = True # This is highlighted in green because it is a keyword. Bool: True, False.\n",
+ "print(b)\n",
+ "print(type(b))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f2421cdb-66a2-49af-9f0a-630be85ef852",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "c = \"True\" # In this case it is a string because we encapsulated it in double quotes \n",
+ "print(c)\n",
+ "type(c)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "16dc4a43-6f9d-4f8d-b946-3fb5e67d4cb3",
+ "metadata": {},
+ "source": [
+ "**Observation**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "38f2e106-8493-4df2-bd0c-9156462ea18b",
+ "metadata": {},
+ "source": [
+ "In Python, Boolean values (True and False) are implicitly treated as integers, with True being equivalent to 1 and False being equivalent to 0."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ad6316eb-49ee-4e30-8160-ffa29594fdba",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(int(True))\n",
+ "print(int(False))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3fae62dd-08db-4d54-a95f-8eb673ebba9b",
+ "metadata": {},
+ "source": [
+ "### Arithmetic Operators "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "1295c68f-a366-4459-80ab-bbc8502842f4",
+ "metadata": {},
+ "source": [
+ "Arithmetic operators are used to perform mathematical calculations on numeric data types.\n",
+ "- (+): Adds values.\n",
+ "- (-): Subtracts values.\n",
+ "- (*): Multiplies values.\n",
+ "- (/): Divides values.\n",
+ "- (//): Performs integer division.\n",
+ "- (%): Returns remainder of division.\n",
+ "- (**): Raises a value to a power.\n",
+ "\n",
+ "Arithmetic operators on strings in Python:\n",
+ "\n",
+ "- Addition (+): Concatenates two strings.\n",
+ "- Multiplication (*): Repeats a string.\n",
+ "- Others (-, /, %, **): Not applicable to strings."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "fe37f3d1-149f-41f4-8c17-f1580420bea8",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x+y"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "606f9b6f-68f9-43e3-b608-83a9c8be226a",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "name = \"Peter\"\n",
+ "surname = \"Pan\"\n",
+ "\n",
+ "name + surname"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "904d03ac-4898-4aab-94d0-9aad79085c3e",
+ "metadata": {},
+ "source": [
+ "### Assignment Operators"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "6fb64855-9d00-4334-bb57-0c6006b24f7e",
+ "metadata": {},
+ "source": [
+ "Assignment operators in Python are used to assign values to variables. They combine the assignment (=) operator with other operators (e.g., +=, -=, *=) to perform arithmetic or logical operations while assigning the result back to the variable."
+ ]
+ },
+ {
+ "cell_type": "raw",
+ "id": "3b3b6151-a1cf-410e-b409-27f22e2ab75d",
+ "metadata": {},
+ "source": [
+ "x += 3 is equivalent to x = x + 3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "cbdd6669-b0a7-4384-a71e-67ee5a4b50f4",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x = 10\n",
+ "x+=3\n",
+ "print(x)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "949f7813-a73e-45ee-996a-165eac50c507",
+ "metadata": {},
+ "source": [
+ "### Comparison Operators"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "4930ea0e-10f2-4df0-973d-60255aa027bf",
+ "metadata": {},
+ "source": [
+ "Comparison operators in Python are used to compare values and return a boolean result (True or False). They include operators such as == (equal to), != (not equal to), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or equal to).\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c22ea0f5-8e8d-40c2-9579-d97184bc7c7a",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x = 10 # Initialize variable `x` with a value 10\n",
+ "y = 5 # Initialize variable `y` with a value 5"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "feee6258-6d7e-40bc-9253-57254618049e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x == y"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e0be9b18-54a3-4a99-b2ad-11c0a72c3568",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x != y"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9ba75c10-4980-490e-97d1-0c60fe7af6af",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x > y"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "48c78ab2-c2ba-4792-af74-673d05cc06bb",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x <= y"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "561b79f4-6ebe-46ac-953c-2e67084eb528",
+ "metadata": {},
+ "source": [
+ "### Logical Operators"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "ddeabd60-2024-4ac4-ab74-2636d5397a8b",
+ "metadata": {},
+ "source": [
+ "Python's logical operators allow you to manipulate logical values (True or False) and make decisions based on conditions. The three logical operators in Python are:\n",
+ "\n",
+ "- `and`: Returns True if both conditions are True, otherwise False.\n",
+ "- `or`: Returns True if at least one condition is True, otherwise False.\n",
+ "- `not`: Negates the logical value of a condition."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "358ff59a-ace0-4cc5-840a-f1112835bf05",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x = 10 # First we will initialize variable `x` with a value 10. \n",
+ "y = 15 # We will initialize variable `y` with a value 15. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "4e0ad684-ff32-4d72-a29f-25b5f19c66ed",
+ "metadata": {},
+ "source": [
+ "Play with the logical operators to look at how they work."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "eb400342-97e9-4717-a352-e456b9921dca",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x < 5 and y < 20 # Returns False since one of the conditions is False, even the other one is True"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b3b30352-b30d-4055-adf1-8d57454f8ff4",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "x < 5 or y < 20 # Returns True since one of the conditions is True, even one is False"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "db7ccb89-00fc-4a68-9ca2-342e8c8f369e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "not(x < 5 or y < 20) # x < 5 or y < 20 is True, so applying not we get False"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d696bfa4-d486-4b91-a715-1c5215b499e5",
+ "metadata": {
+ "tags": []
+ },
+ "source": [
+ "### Data Type Compatibility and Casting"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a5b3bf87-aaf6-4530-85e7-938ea321c260",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "1+\"hello\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3c8aa343-4b83-4b25-a4db-6d982a136003",
+ "metadata": {},
+ "source": [
+ "Different data types in Python have specific rules for how they can be used together. Performing operations with incompatible data types can result in errors if the computer doesn't know how to perform it. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "edf71839-14e4-4f6d-a856-0968ea7b0dab",
+ "metadata": {},
+ "source": [
+ "Data type casting in Python allows you to convert values from one type to another, as long as the computer knows how to do it (as long as it makes sense to do so). You can use the following functions for type conversion:\n",
+ "\n",
+ "- `int()`: Converts a value to an integer.\n",
+ "- `float()`: Converts a value to a float.\n",
+ "- `str()`: Converts a value to a string.\n",
+ "- `bool()`: Converts a value to a boolean."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a2d0aee0-8e1e-481b-95b3-419473ea13ec",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Integer to float\n",
+ "x = 5\n",
+ "y = float(x)\n",
+ "print(y) # Output: 5.0"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "25dbcfbf-4659-44b5-8258-242ab03f37f2",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Float to integer\n",
+ "a = 3.8\n",
+ "b = int(a)\n",
+ "print(b) # Output: 3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a45960ce-8a0c-4e34-8e5f-f3395f8c7444",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# String to integer\n",
+ "c = \"10\"\n",
+ "d = int(c)\n",
+ "print(d) # Output: 10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0dd2d7ce-b162-4fd0-b4dd-552d5906ce15",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Boolean to string\n",
+ "e = True\n",
+ "f = str(e)\n",
+ "print(f) # Output: \"True\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a8cbf612-31f9-4eb6-88ae-72e89fd9fa6b",
+ "metadata": {
+ "tags": []
+ },
+ "source": [
+ "## String methods and functions"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3825dd52-176e-4b08-8f5a-72a7e855246d",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "text = \"Hello, World!\"\n",
+ "\n",
+ "# Length of a string\n",
+ "length = len(text)\n",
+ "print(length) # Output: 13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a0d62811-5676-4a8c-8cff-940e39a3ad9c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Lowercase and uppercase\n",
+ "lowercase = text.lower()\n",
+ "uppercase = text.upper()\n",
+ "print(lowercase) # Output: \"hello, world!\"\n",
+ "print(uppercase) # Output: \"HELLO, WORLD!\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e2945736-21a7-4e6f-87cd-0768951858e9",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Stripping whitespace\n",
+ "stripped = text.strip()\n",
+ "print(stripped) # Output: \"Hello, World!\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "03d72a98-3658-4fec-8a26-782a73babca2",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Splitting and joining strings\n",
+ "split_list = text.split(\",\")\n",
+ "joined_string = \"-\".join(split_list)\n",
+ "print(split_list) # Output: ['Hello', ' World!']\n",
+ "print(joined_string) # Output: \"Hello- World!\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "987fab01-7f26-4a11-a120-ae2f4eef24cb",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Replacing substrings\n",
+ "replaced = text.replace(\"Hello\", \"Hi\")\n",
+ "print(replaced) # Output: \"Hi, World!\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e1cd8347-8ab3-4b7f-ba5b-6a3709034a48",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Finding substrings\n",
+ "index = text.find(\"World\")\n",
+ "print(index) # Output: 7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "8f117912-e487-4a1a-93e9-b94a8da048c9",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Checking start and end of string\n",
+ "starts_with_hello = text.startswith(\"Hello\")\n",
+ "ends_with_world = text.endswith(\"World!\")\n",
+ "print(starts_with_hello) # Output: True\n",
+ "print(ends_with_world) # Output: True"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c8e5fa40-7c11-4e77-9fd1-9dc90aa9dc99",
+ "metadata": {},
+ "source": [
+ "### Formatting Strings"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "e4962711-4fa0-45b3-b486-43ca59736b9a",
+ "metadata": {},
+ "source": [
+ "Let's look at different ways to format strings in Python. String formatting allows you to incorporate variables or values into a string in a structured and readable manner.\n",
+ "\n",
+ "We'll look at three ways:\n",
+ "\n",
+ "1. The first example uses f-strings (formatted string literals), denoted by the 'f' at the beginning of the string. Inside the curly braces, you can include variables or expressions that will be evaluated and replaced with their respective values when the string is created."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "39b2c29a-31ed-4473-9d59-923144e99631",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "name = \"Sam\"\n",
+ "age = 20\n",
+ "\n",
+ "greeting = f\"Hello my name is {name}, and my age is {age}\" #f in the beginning\n",
+ "greeting"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "22e6bc39-2e31-4c25-8e59-555351158f56",
+ "metadata": {},
+ "source": [
+ "2. The second example uses the `format` method to insert the value of the variable `name` into the string. Within the string, you will find a placeholder `{}` where the value will be placed. The `format` method is called on the string and takes the value to be inserted as an argument."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c1de1fa8-6f77-4d63-b891-0af08348848b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "greeting_2 = \"Hello my name is {}\".format(name) #format in the end \n",
+ "greeting_2"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "af664ac1-bc02-4910-9acf-6073796cd6c3",
+ "metadata": {},
+ "source": [
+ "3. The third example demonstrates simple concatenation. The string \"Hello my name is\" is concatenated with a space and the variable `name` using the `+` operator."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b6520eb5-93fe-4eed-ad2f-4c311bf94c90",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "greeting_3 = \"Hello my name is\" + \" \" + name\n",
+ "greeting_3"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3ff8ff64-1add-44a2-8c45-edd9e04d80dc",
+ "metadata": {},
+ "source": [
+ "### Input and output functions\n",
+ "\n",
+ "Input and output are concepts in programming that allow us to interact with the user and display information on the screen. In Python, we commonly use the console as the standard input and output device.\n",
+ "\n",
+ "**Input**:\n",
+ "To get input from the user, we use the `input()` function. It displays a message on the console and waits for the user to enter a value. The value entered by the user is returned as a **string**.\n",
+ "\n",
+ "Here's an example:\n",
+ "```python\n",
+ "name = input(\"Enter your name: \")\n",
+ "print(\"Hello, \" + name + \"!\")\n",
+ "```\n",
+ "In this example, the `input()` function displays the message \"Enter your name: \" on the console. The user can then enter their name, and the input is assigned to the variable `name`. Finally, the program prints a greeting message using the entered name.\n",
+ "\n",
+ "**Output**:\n",
+ "To display information or results on the console, we use the `print()` function. It takes one or more values as arguments (**strings**) and displays them as output.\n",
+ "\n",
+ "Here's an example:\n",
+ "```python\n",
+ "age = 25\n",
+ "print(\"Your age is:\", age)\n",
+ "```\n",
+ "In this example, the `print()` function displays the string \"Your age is:\" followed by the value of the `age` variable. The output will be \"Your age is: 25\".\n",
+ "\n",
+ "You can also format the output using placeholders or string concatenation, as shown in the previous examples."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a7ef9599-cdc9-446d-8872-ed23745c7e22",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "name = input(\"Please enter your name: \")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f885ac1a-fbba-4dd9-a9b8-67812ab278d6",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "age = input(\"This is my age: \")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7b7cb22f-a423-40ed-9038-d953f28d75cb",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "type(age)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "407d2fc7-0ebf-4601-ab33-35f94edba027",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "random = input()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "507aae69-f418-4f81-a538-a239320dbd17",
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [],
+ "source": [
+ "age_2 = int(input(\"Enter only a digit: \"))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "689dfc35-396f-4d7d-b915-75e747cd133f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "type(age_2)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "56148c6d-d9c7-4b30-9223-8e5532c48423",
+ "metadata": {},
+ "source": [
+ "When using the `print()` function in Python, it's important to note that it does not have a return value. If you assign the result of a `print()` statement to a variable or return it in a function, the value will be `None`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "74c1a433-222c-4a07-b69a-32be13b288f9",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "n = print(\"Hi\") #here we dont print the value of n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7996ce7d-c9d2-44ea-91aa-193e757f2413",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(n) #lets look at the value of n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "650b4a94-6a3e-4a82-9359-c53d92766a7e",
+ "metadata": {},
+ "source": [
+ "### π‘ Check for understanding\n",
+ "\n",
+ "Create a program that asks the user to enter their age. The program should then calculate and display the user's age after 10 years.\n",
+ "\n",
+ "Instructions:\n",
+ "1. Prompt the user to enter their age using the `input()` function and store it in a variable.\n",
+ "2. Convert the user's input from a string to an integer using the `int()` function and store it in another variable.\n",
+ "3. Add 10 to the user's age using the `+` operator and store the result in a third variable.\n",
+ "4. Display the user's age after 10 years by printing the result.\n",
+ "\n",
+ "Example Output:\n",
+ "Enter your age: 25\n",
+ "Your age after 10 years: 35\n",
+ "\n",
+ "Note: Ensure that you handle any potential errors related to casting."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7f52e656-21a5-412a-b56a-0f8805366f49",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code goes here"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5299fd13-4e98-45c7-84f2-48a5538bead3",
+ "metadata": {
+ "tags": []
+ },
+ "source": [
+ "## Data structures "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "58ae4a1d-6039-4f07-b159-9df5fcd2f78e",
+ "metadata": {},
+ "source": [
+ "Data structures are fundamental components in programming that provide a way to manage and **work with collections of values** or entities. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "7f2bedf8-c0fc-4456-b75f-b0347a4e7256",
+ "metadata": {},
+ "source": [
+ "Data structures in Python can be categorized as either mutable or immutable.\n",
+ "\n",
+ "- **Mutable** data structures, like lists, dictionaries, and sets, can be modified after they are created.\n",
+ "- **Immutable** data structures, such as strings and tuples, cannot be changed once defined."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "2e1caa66-2b83-4140-b38c-5ce1e8905d8c",
+ "metadata": {},
+ "source": [
+ "Python Data Structures:\n",
+ "- **Lists**: Ordered, mutable collections that store elements of different types and allow indexing, appending, removing, and modifying. [ ]\n",
+ "- **Dictionaries**: Ordered (from Python 3.6), mutable key-value pairs for efficient lookup and organization of data. { }\n",
+ "- **Sets**: Unordered, mutable collections of unique elements with set operations like union and intersection. { }\n",
+ "- **Tuples**: Ordered, immutable collections commonly used for fixed values. ( )"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "4d1afcd5-c5df-4997-986c-7dcf26773a75",
+ "metadata": {},
+ "source": [
+ "## Lists"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "ee2daf21-6f62-4894-b26e-1daf7cca89cb",
+ "metadata": {},
+ "source": [
+ "To create a list, you can simply assign a sequence of elements to a variable using the square brackets notation."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7e458d22-4aa7-433d-a4c1-2acf4e499df5",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "fruits = [\"apple\", \"banana\", \"orange\", \"pineapple\", \"strawberry\"]\n",
+ "vegetables = [] # To create an empty list, you can simply assign square brackets.\n",
+ "print(fruits)\n",
+ "print(vegetables)\n",
+ "type(fruits)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c1c535b5-0af5-4a25-8b80-e9334089b51c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Lists can hold elements of different type\n",
+ "example1 = [1 , 'a', True] # Integer, string and boolean\n",
+ "example1"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "247eb050-d743-4747-b10b-34ffaddc5333",
+ "metadata": {},
+ "source": [
+ "### Indexing and slicing"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d52e7632-b450-413f-934d-9a17af6e0bbf",
+ "metadata": {},
+ "source": [
+ "In Python, indexing allows you to access elements within a list using their unique index values. Indexing syntax is as follows:\n",
+ "\n",
+ "```python\n",
+ "list_name[index]\n",
+ "```\n",
+ "\n",
+ "The index starts from 0 for the first element and can also be negative to refer to elements from the end of the list (e.g., -1 for the last element)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "72cb0ec6-7a8d-436c-af9e-860ec95df4c7",
+ "metadata": {},
+ "source": [
+ "#### Slicing"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d31d9634-14ca-4ced-8e0e-ad16ce634a80",
+ "metadata": {},
+ "source": [
+ "In Python, slicing allows you to extract a portion of a sequence using the syntax `sequence[start:end:step]`. The `start` index is inclusive, the `end` index is exclusive, and the `step` value (optional) controls the increment between elements in the slice. \n",
+ "\n",
+ "Note that if you omit a value, such as `x[:stop]`, it is automatically replaced with a default value: the first element for `start`, the last element for `end`, and `1` for `step`."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "836a8d24-29ff-4cc6-89e6-562a1ce789e4",
+ "metadata": {},
+ "source": [
+ "
"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "83bdbbd2-e8c8-4687-81df-d41906352ebf",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "fruits[0] #Note that the index starts in 0"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5d9a1188-8e6b-4d98-bba0-0e87677d7df4",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "fruits[:2] # Returns a new list which includes elements at indices 0,1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7687c4e1-e5c7-4447-a683-a32ea6f086d0",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "fruits[1:4:2] # Returns a new list, which includes elements at indices 1, 3"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "4046120b-1143-4979-84f3-7e65e656bb9c",
+ "metadata": {},
+ "source": [
+ "### Modifying List Elements\n",
+ "\n",
+ "Lists are mutable, meaning you can modify their elements after creation. You can assign new values to specific elements using their index."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "02c65c42-e5e6-4382-ae11-508a3b7b04e5",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "fruits[1] = \"grape\"\n",
+ "fruits "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d2750a99-22c5-4d89-9043-10062b5c7c01",
+ "metadata": {},
+ "source": [
+ "### List Operators and functions\n",
+ "\n",
+ "Lists support various operations, such as concatenation (+) to combine two lists or repetition (*) to repeat a list."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e322817e-499f-48f7-be5b-17bfdf948104",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "my_list = [1, 2, 3]\n",
+ "combined = fruits + my_list\n",
+ "combined"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "8601408f-08dd-4967-8027-6501d93c29c1",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# len() gives the number of elements in the list.\n",
+ "length = len(my_list) \n",
+ "print(length) # Output: 3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "de16babe-c8d7-459e-a143-8fbb203623cc",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# append() adds an element at the end of the list\n",
+ "my_list.append(4)\n",
+ "print(my_list) # Output: [1, 2, 3, 4]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3c9e4aea-fa11-4482-8609-fff513dd5b21",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# insert() inserts an element in a position\n",
+ "my_list.insert(2, 5)\n",
+ "print(my_list) # Output: [1, 2, 5, 3, 4]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "cb9c4af6-3e9a-4dfc-94e8-cd624e91ad4c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# remove() removes an element\n",
+ "my_list.remove(3)\n",
+ "print(my_list) # Output: [1, 2, 5, 4]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b930cde8-e6cf-4cb8-9cfb-9838da629479",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# pop() removes an element and returns it\n",
+ "popped_element = my_list.pop(2)\n",
+ "print(popped_element) # Output: 5\n",
+ "print(my_list) # Output: [1, 2, 4]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "03f4b879-e5af-42a2-b6fe-edb2dce7a1cd",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# index() returns the index at which that element is\n",
+ "index = my_list.index(2)\n",
+ "print(index) # Output: 1"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ae777f7a-17aa-4ef8-8f29-2c121ef44836",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# sort() sorts the list in ascending order\n",
+ "fruits.sort() "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "fe9232d2-92c3-4c80-b21b-6369763bee8b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# min(), max()\n",
+ "print(min(my_list), max(my_list))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a18f13da-24e3-4d49-a992-df63e7802495",
+ "metadata": {},
+ "source": [
+ "### π‘ Check for understanding\n",
+ "\n",
+ "Look at the error we get if we execute the following line again. Why do you think it is?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5988d2f1-cdf3-4354-a88d-bf0cdf6c3550",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "my_list.remove(3) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b8abd190-21ed-44d8-b66c-e33331334f5f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "sentence = \"Hello, world! This is a test.\"\n",
+ "\n",
+ "# Split the sentence into a list of words\n",
+ "words = sentence.split() # words = ['Hello,', 'world!', 'This', 'is', 'a', 'test.']\n",
+ "\n",
+ "# Sort the words in reverse order\n",
+ "reversed_words = sorted(words, reverse=True) # reversed_words = ['world!', 'This', 'test.', 'is', 'Hello,', 'a']\n",
+ "\n",
+ "# Join the reversed words into a single sentence\n",
+ "reversed_sentence = \" \".join(reversed_words) # reversed_sentence = 'world! This test. is Hello, a'\n",
+ "\n",
+ "# Print the reversed sentence\n",
+ "print(reversed_sentence) # Output: 'world! This test. is Hello, a'\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f6854f7a-87c4-4954-8f27-b70e2b2207e6",
+ "metadata": {},
+ "source": [
+ "Note: The method `sort()` is a list method that sorts the list in-place, while the function `sorted()` is a built-in Python function that returns a new sorted list without modifying the original list."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "41b4719e-5d86-4eb7-ac6d-c103f210420f",
+ "metadata": {},
+ "source": [
+ "## Dictionaries "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "31594a7d-b5d4-480c-94bc-8657361b9b12",
+ "metadata": {},
+ "source": [
+ "In Python, dictionaries are created using curly braces {} and consist of key-value pairs separated by commas. Keys in a dictionary must be unique, and if a key already exists, assigning a new value to that key will overwrite the existing value."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ddd96d75-81f5-4564-9872-7f2ea5354613",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Lets add two 'John' keys with different values\n",
+ "contacts = {'John': '312-555-1234', 'John': '111-111-1234', 'Paul': '312-555-3123', 'George': '312-555-3333', 'Ringo': '312-555-2222'}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6fe7cfd8-6134-4ae0-93a7-d06094534d18",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts # We can see that it only kept one 'John' with the latest value"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "6dc7b2bd-e15f-4f9d-8702-906dd24f39c7",
+ "metadata": {},
+ "source": [
+ "### Accessing values using the keys"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c266d2c8-0a13-4914-952e-094e8dafb858",
+ "metadata": {},
+ "source": [
+ "To access values in a dictionary, use the corresponding key in square brackets [], noting that keys are case-sensitive."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f31903f7-1252-404b-b803-e91bcd56664b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts['John'] # This is very similar to lists except that here we are using keys as indexes"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "bb0be463-f1b1-4e21-b652-9975096c1a4e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts['PAUL'] # We get a KeyError since the key PAUL is not in the dictionary"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c6436cc8-c6c3-4f23-9799-a2e407fa762b",
+ "metadata": {},
+ "source": [
+ "### Adding and Modifying Values\n",
+ "\n",
+ "To add a new key-value pair to a dictionary, use the syntax `[] = value`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e2643426-26a5-46e2-bf2b-3e1e1b411b8b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts['Mel'] = '480-111-2222'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a8daaff0-14ba-400b-96e2-574ea799aa10",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts # Mel was added to the dictionary"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f2934ca2-c934-41e1-b41b-18b1c1667de8",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts['Mel'] = '480-999-8888'\n",
+ "contacts # Mel value (number) was modified"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "232d29c6-d3b5-43fe-b78a-d4b21cbf0c81",
+ "metadata": {},
+ "source": [
+ "Values inside a dictionary can be any data type, including lists or dictionaries itself."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "24a025a9-97ca-4302-b63b-267a952c9600",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "student_data = {\n",
+ " 'Name': 'John', \n",
+ " 'E-mail': 'john@gmail.com', \n",
+ " 'Age': 28, \n",
+ " 'subjects': ['math', 'science', 'history', 'geography'] \n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "eef6cc0d-3b4c-48e0-9c45-9a54607d7dc5",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "student_data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "13d94cc6-33d9-4d8b-b151-8d51ce551223",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Remember that the keys are case sensitive \n",
+ "student_data['subjects']"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b70a4adb-82b6-4599-998a-a2937d430dfa",
+ "metadata": {},
+ "source": [
+ "**Note**: Value associated with the key 'subjects' is a list. According to this, if we want to access 'science', we need first to access the `subjects` key in the dictionary. Then, as the `value` is a list, we need to access the corresponding element of the list.\n",
+ "\n",
+ "To access the value 'science' in the `student_data` dictionary, you can use the expression `student_data['subjects'][1]`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "8ca10f21-f39e-4a1d-a726-7e820f1b3181",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "student_data['subjects'][1] "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c7b44f4f-0e56-4753-a8dd-23cf93160c23",
+ "metadata": {},
+ "source": [
+ "### Removing Values\n",
+ "\n",
+ "You can remove a key-value pair from a dictionary using the `del` keyword or the `pop` method."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e6031b9f-0ca9-43ea-8cf6-132028e57152",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "del contacts[\"Mel\"]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6daecca3-8387-4cd2-a274-7c94a68c0b84",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2643162b-8193-46b7-af02-609a25aa3e8c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts.pop('John')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "90903cb7-7644-4702-9321-f8464f89faed",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "341c8a07-81d4-43e5-a40e-26a9b0053a33",
+ "metadata": {},
+ "source": [
+ "### Checking Key Existence\n",
+ "\n",
+ "To check if a key exists in a dictionary, you can use the `in` keyword:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "07046873-9b8a-4446-a48b-bfd9c935cd20",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "if \"John\" in contacts:\n",
+ " print(\"Yes, 'John' is in the dictionary.\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "37d42539-6e81-4aed-98f8-3f70ffc0e992",
+ "metadata": {},
+ "source": [
+ "### Dictionary Methods"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "18885f64-dce9-4375-a4b1-37df897855cc",
+ "metadata": {},
+ "source": [
+ "Python dictionaries provide several useful methods:\n",
+ "- **`.keys()`**: Returns a view object containing all the keys in the dictionary.\n",
+ "- **`.values()`**: Returns a view object containing all the values in the dictionary.\n",
+ "- **`.items()`**: Returns a view object containing all the key-value pairs in the dictionary as tuples.\n",
+ "- **`get(key)`**: Returns the value associated with the specified key. If the key is not found, it returns a default value (None by default) instead of raising an error."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f892574d-7801-4e1d-b52d-cfab6fc5daf4",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts.keys()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a4cb265f-be0a-4f56-94bc-bc2585a64d52",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts.values() # But this directly does not tell us to which keys these values are associated "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "8d943745-886a-4dea-965b-2e552e78c803",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts.items()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "32fca515-2fa7-4394-b98a-2c6e44f4d5a3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts.get('John')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a6ea759c-fac4-4768-8160-7ea530df7037",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(contacts.get('Anna', 'Not found'))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ec475c8b-b2b5-4c87-afc1-2ced5166a10f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(contacts.get('Anna'))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5108d421-4f84-454a-81fe-c0b26759aba5",
+ "metadata": {},
+ "source": [
+ "In Python, the `print()` function displays the value passed to it and outputs it to the console. If the value is `None`, the function explicitly displays the word `None` as the output. In Jupyter Notebook, variables are automatically displayed as output when mentioned in a cell, but if the value is `None`, the notebook environment shows nothing instead of displaying `None`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e93d2989-34c2-48bc-a8d0-3f6bc34b1068",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "contacts.get('Anna')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "09533aba-5aaa-4316-b8ae-29313652c73c",
+ "metadata": {},
+ "source": [
+ "## Sets\n",
+ "\n",
+ "Sets in Python are unordered collections of unique elements defined using curly braces {} or the set() function. They can contain elements of different data types, do not allow duplicates, and are mutable. Sets support operations like union, intersection, and difference."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3ef68f3a-ddc1-433e-833a-d73ee319a349",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Creating a set\n",
+ "fruits = {'apple', 'banana', 'orange'}\n",
+ "print(fruits) # Output: {'apple', 'banana', 'orange'}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "998f4e4f-a82c-480c-bed9-eaf13da5e424",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Adding elements to a set\n",
+ "fruits.add('grape')\n",
+ "print(fruits) # Output: {'apple', 'banana', 'orange', 'grape'}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "4e7f9196-58c8-4e19-80da-1bc0827f5d63",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Removing elements from a set\n",
+ "fruits.remove('banana')\n",
+ "print(fruits) # Output: {'apple', 'orange', 'grape'}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5d3c982e-45e5-40e7-ba11-13bfbef2ab88",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "set_1 = {1, 2, 3}\n",
+ "set_2 = {3, 4, 5}\n",
+ "\n",
+ "# Union of set_1 and set_2\n",
+ "union = set_1.union(set_2)\n",
+ "print(union) # Output: {1, 2, 3, 4, 5}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "cdfe6d94-0d49-4823-83b6-0bec309b5c72",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Alternative union syntax using the pipe symbol |\n",
+ "union_alt = set_1 | set_2\n",
+ "print(union_alt) # Output: {1, 2, 3, 4, 5}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c83c0155-59d4-4816-b7df-eb111da9699f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Intersection of set_1 and set_2\n",
+ "intersection = set_1.intersection(set_2)\n",
+ "print(intersection) # Output: {3}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "082870d7-5cbc-4942-a8ff-021a63fe1116",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Alternative intersection syntax using the ampersand symbol &\n",
+ "intersection_alt = set_1 & set_2\n",
+ "print(intersection_alt) # Output: {3}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "74140a59-8f82-4b6e-af46-9c192f84055f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Difference of set_1 and set_2 (elements in set_1 but not in set_2)\n",
+ "difference = set_1 - set_2\n",
+ "print(difference) # Output: {1, 2}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c47e538d-d047-4468-9dee-cb1dff9d1ac6",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Subset check (whether set_1 is a subset of set_2)\n",
+ "is_subset = set_1.issubset(set_2)\n",
+ "print(is_subset) # Output: False"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5c6f9ada-6dd4-4131-8754-e5097570c354",
+ "metadata": {},
+ "source": [
+ "## Tuples\n",
+ "\n",
+ "Tuples are immutable and defined using parentheses (). They can store elements of different types, and once created, their elements cannot be modified. Tuples are often used to group related data together."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "cee6451b-a0f4-4701-ad28-a1ef0a7dcfad",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Creating a tuple\n",
+ "person = ('John', 25, 'USA')\n",
+ "print(person) # Output: ('John', 25, 'USA')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "8af21089-5475-40d4-89aa-20cd87a6fe6f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Accessing elements of a tuple\n",
+ "name = person[0]\n",
+ "age = person[1]\n",
+ "print(name, age) # Output: John 25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c05c3ee8-5f6e-4645-b72f-274b267ed1bd",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Trying to modify a tuple (this will raise an error)\n",
+ "person[0] = 'Jane'"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c2118725-cfaa-4841-8069-cc61da69b3be",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "person.append(0) # 'tuple' object has no attribute 'append'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f1d43f6e-6746-4488-b6a3-aabe1a57bf46",
+ "metadata": {},
+ "source": [
+ "## Summary\n",
+ "\n",
+ "It is always crucial to know what kind of variable you have in your hands because this determines how to retrieve the data. \n",
+ "\n",
+ "- lists and tuples -> accessed by **index**\n",
+ "- dictionaries -> accessed by **key** (misleadingly, the key can be a number but usually is a string)\n",
+ "- sets -> since sets are unordered, they do not support indexing or retrieval of elements by position\n",
+ "\n",
+ "\n",
+ "To identify these types:\n",
+ "- Lists are easily recognizable as they begin and end with square brackets `[ ]`.\n",
+ "- Dictionaries are enclosed in curly brackets `{ }`.\n",
+ "- Sets are also enclosed in curly brackets `{ }`, but they lack key-value pairs.\n",
+ "- Tuples are indicated by parentheses `( )`."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "1e02990b-5522-4ee2-aa1e-c9e3b7b2601c",
+ "metadata": {},
+ "source": [
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "08143668-d89c-40a4-8e3d-4058f0a6b66d",
+ "metadata": {},
+ "source": [
+ "## π‘ Check for understanding"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "81d83946-739d-47b6-949d-3d80322f8c47",
+ "metadata": {},
+ "source": [
+ "Write a program that allows the user to enter the grades of five students. The program should store these grades in a list and then display the average grade."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f29748e1-523c-4ba3-a74c-c17d4314717e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Write your code here"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "05fb5689-6131-4ebb-97af-6408f8813217",
+ "metadata": {},
+ "source": [
+ "**Please refer to the following hint only if you have attempted the Check for Understanding and are still confused. Do not read it before giving it a try.**:\n",
+ "\n",
+ "Here's a step-by-step guide:\n",
+ "\n",
+ "1. Create an empty list to store the grades.\n",
+ "2. Use the `input()` function to get the grade from the user for each student. Append each grade to the list.\n",
+ "3. Calculate the average grade by summing up all the grades in the list and dividing by the number of grades.\n",
+ "4. Display the average grade to the user."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "6aabbf00-3eba-412b-860a-e7f9727ff71e",
+ "metadata": {},
+ "source": [
+ "# Extra: nested dictionaries "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5f25699d-f74f-4136-90e6-2bf44d44d967",
+ "metadata": {},
+ "source": [
+ "In Python, a nested dictionary is a dictionary where the values are themselves dictionaries. This can be useful when you need to organize data into multiple levels or categories. Here are some key points about nested dictionaries:\n",
+ "\n",
+ "- A nested dictionary can have multiple levels of nesting, with each level representing a specific category or subcategory.\n",
+ "- You can access the values in a nested dictionary by specifying the keys at each level.\n",
+ "- You can add, modify, or remove elements from a nested dictionary, just like with regular dictionaries.\n",
+ "- Each level of a nested dictionary can have different keys and values, providing flexibility in structuring your data.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "89c96830-96e2-4178-b3a1-8afed9b641e4",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Creating a nested dictionary\n",
+ "student_data = {\n",
+ " 'John': {\n",
+ " 'age': 20,\n",
+ " 'major': 'Computer Science',\n",
+ " 'grades': [85, 90, 78]\n",
+ " },\n",
+ " 'Jane': {\n",
+ " 'age': 22,\n",
+ " 'major': 'Biology',\n",
+ " 'grades': [92, 88, 95]\n",
+ " }\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a25cd58c-19dc-4e35-b133-3b4b1ae61321",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Accessing values in a nested dictionary\n",
+ "john_age = student_data['John']['age']\n",
+ "jane_major = student_data['Jane']['major']\n",
+ "john_grades = student_data['John']['grades']\n",
+ "\n",
+ "print(john_age) # Output: 20\n",
+ "print(jane_major) # Output: Biology\n",
+ "print(john_grades) # Output: [85, 90, 78]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a7bf9651-8ca7-4809-9f2b-ac77ec1b868a",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Modifying values in a nested dictionary\n",
+ "student_data['John']['major'] = 'Electrical Engineering'\n",
+ "student_data['Jane']['grades'].append(97)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6c496256-0870-4455-96a9-0aefa9bd6c31",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Adding a new student to the nested dictionary\n",
+ "student_data['Sarah'] = {\n",
+ " 'age': 19,\n",
+ " 'major': 'Physics',\n",
+ " 'grades': [90, 91, 88]\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "870021a8-0342-4068-8569-102655de8152",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Removing a student from the nested dictionary\n",
+ "del student_data['John']\n",
+ "\n",
+ "print(student_data)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "bd09ff80-cfac-48ab-a78d-e653bf9d85f0",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "student_data.keys()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a049c2d5-d318-4f0e-95e2-5d3945e84def",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "student_data.values()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "da05cac7-13d8-4ecd-bb6e-c244c29ede11",
+ "metadata": {},
+ "source": [
+ "As you can see, the `keys` of a dictionary can be either:\n",
+ "\n",
+ "- strings \n",
+ "- numbers\n",
+ "\n",
+ "In this above example, the dictionary `keys` which are strings. In this particular case, the `values` are also dictionaries."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3f9406c7-6da3-430f-a99c-db109cced171",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "student_data[\"Jane\"].keys()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2b9ec1e3-7e34-4340-863f-09b442c113ba",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "student_data[\"Jane\"].values()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "12cf0a81-5f6b-434b-aef2-ebb9afc191ce",
+ "metadata": {},
+ "source": [
+ "π‘Check for understanding: how would you access the first grade of Jane?"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "607b21fe-fbd6-430a-b94e-df80ee7864f7",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Try it yourself here"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "2976667a-d51a-4188-ba3a-67a47097d071",
+ "metadata": {},
+ "source": [
+ "We mentioned nested dictionaries (dictionaries inside dictionaries) but as you can see in the example, we can also have lists inside dictionaries. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b1f00c61-f13c-4155-a7d4-d663de273a44",
+ "metadata": {},
+ "source": [
+ "You can also have lists in which each element is a dictionary. Therefore the amount of possible combinations and levels of nesting is endless."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "78d88957-0a66-4df7-b656-5edaeaf43a6c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "my_data = [{'Mike': [25,23000],'Jane': [38, 40000],'Bill': [45,35000]},{'Developers': ['Mike','Bill']},{'HR': ['Jane']}]\n",
+ "my_data"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b6a957c4-d529-4fa9-a1d2-dfea3e59adcc",
+ "metadata": {},
+ "source": [
+ "This is an example of a nested list with three elements, and each element is a dictionary. When working with nested data structures like this, it is important to understand the type of variable you are dealing with.\n",
+ "\n",
+ "Let's check the type of the variable `my_data`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "1482c0ca-8477-4b4b-8e15-c5a137a62bf9",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "type(my_data)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a87a5836-1c86-4a1e-8a12-5201daa9e4b5",
+ "metadata": {},
+ "source": [
+ "Let's access the first element of the list. Since the variable is a **list**, we use **indexing**. Indexing allows us to retrieve specific elements from a list by their position. In this case, to access the first element, we use the index 0 since Python starts counting from 0."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "247f2ac8-bcaf-46f8-bd70-25a9e51e69eb",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "my_data[0]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "88fe62d8-d888-4e97-8856-959ee1bd47aa",
+ "metadata": {},
+ "source": [
+ "This element is a dictionary, which can be determined by its structure and the presence of key-value pairs. However, if you're unsure about the data type, you can use the `type()` function to confirm it."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9a049816-1098-4799-82a8-003fa5ccd263",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "type(my_data[0])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "635d4205-cc13-4a0b-aa87-c0898da9d3dd",
+ "metadata": {},
+ "source": [
+ "Now let's access the data of 'Jane'. Since this element is a **dictionary**, we need to access its values using the corresponding **keys**."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "062356f6-f02c-4d11-9dd0-2e55cfa438b8",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "my_data[0]['Jane']"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "089625c7-dfd1-4b7a-b490-9821eb84572d",
+ "metadata": {},
+ "source": [
+ "As we can see, we get another **list**. To access the last element of this list, we can use its **index**."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9bd9d9ac-91c9-48df-8973-18de70bfa330",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "type(my_data[0]['Jane']) # Let's make sure its a list"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "fefcc28d-84b9-4e6e-815b-e924a99ff32e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "my_data[0]['Jane'][1]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b7107a1a-b95b-4af4-bff4-91a42d435d55",
+ "metadata": {},
+ "source": [
+ "# Extra: \"is\" vs \"==\" "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "644820c4-1c6a-4793-8153-4a34d6b822de",
+ "metadata": {},
+ "source": [
+ "- `==` compares the values of two objects and returns `True` if they are equal.\n",
+ "- `is` compares the identity of two objects and returns `True` if they refer to the same object in memory.\n",
+ "- `id()` is a built-in function in Python that returns the unique identifier (memory address) of an object. Each object has a distinct `id()` value, allowing us to differentiate between different objects even if they have the same values."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "4733a76e-fa9f-4c21-b277-3ecca378139c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "a = [1, 2]\n",
+ "b = [1, 2]\n",
+ "\n",
+ "# Comparing the values of a and b using ==\n",
+ "print(a == b) # True (Both lists have the same values)\n",
+ "\n",
+ "# Comparing the identity of a and b using is\n",
+ "print(a is b) # False (a and b are different objects in memory)\n",
+ "\n",
+ "# Printing the unique identifier (memory address) of a and b\n",
+ "print(id(a))\n",
+ "print(id(b))\n",
+ "\n",
+ "# Assigning b to a\n",
+ "a = b\n",
+ "\n",
+ "# Comparing the identity of a and b again after assignment\n",
+ "print(a is b) # True (a and b now refer to the same object)\n",
+ "\n",
+ "# Printing the updated memory addresses of a and b\n",
+ "print(id(a))\n",
+ "print(id(b))\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ },
+ "toc": {
+ "base_numbering": 1,
+ "nav_menu": {},
+ "number_sections": true,
+ "sideBar": false,
+ "skip_h1_title": false,
+ "title_cell": "Table of Contents",
+ "title_sidebar": "Contents",
+ "toc_cell": true,
+ "toc_position": {
+ "height": "537.273px",
+ "left": "1007.99px",
+ "top": "110.824px",
+ "width": "261.818px"
+ },
+ "toc_section_display": true,
+ "toc_window_display": true
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
\ No newline at end of file
diff --git a/file1.py b/file1.py
new file mode 100644
index 00000000..e69de29b
diff --git a/file2.py b/file2.py
new file mode 100644
index 00000000..e69de29b
diff --git a/file3.py b/file3.py
new file mode 100644
index 00000000..e69de29b
diff --git a/file4.py b/file4.py
new file mode 100644
index 00000000..e69de29b
diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb
index 5b3ce9e0..33fc8028 100644
--- a/lab-python-data-structures.ipynb
+++ b/lab-python-data-structures.ipynb
@@ -50,13 +50,142 @@
"\n",
"Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. "
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 14,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ " products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "inventory = {} "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdin",
+ "output_type": "stream",
+ "text": [
+ "Please enter the quantity for t-shirt: 4\n",
+ "Please enter the quantity for mug: 9\n",
+ "Please enter the quantity for hat: 6\n",
+ "Please enter the quantity for book: 7\n",
+ "Please enter the quantity for keychain: 8\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "{'t-shirt': 4, 'mug': 9, 'hat': 6, 'book': 7, 'keychain': 8}\n"
+ ]
+ }
+ ],
+ "source": [
+ "for product in products:\n",
+ " key_input = input(f\"Please enter the quantity for {product}: \")\n",
+ " inventory[product] = int(key_input)\n",
+ " \n",
+ "print(inventory)\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdin",
+ "output_type": "stream",
+ "text": [
+ "Please enter name of items from the products list ['t-shirt', 'mug', 'hat', 'book', 'keychain']: book\n",
+ "Please enter name of items from the products list ['t-shirt', 'mug', 'hat', 'book', 'keychain']: mug\n",
+ "Please enter name of items from the products list ['t-shirt', 'mug', 'hat', 'book', 'keychain']: hat\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "{'book', 'hat', 'mug'}\n"
+ ]
+ }
+ ],
+ "source": [
+ "customer_orders = set()\n",
+ "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
+ "\n",
+ "for i in range(3):\n",
+ " product = input(f\"Please enter name of items from the products list {products}: \") \n",
+ " if product in products: \n",
+ " customer_orders.add(product)\n",
+ " else:\n",
+ " print(f\"{product} is not in the product list. Please try again.\")\n",
+ "\n",
+ "print(customer_orders) \n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import statistics"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "SyntaxError",
+ "evalue": "unmatched ')' (180260199.py, line 5)",
+ "output_type": "error",
+ "traceback": [
+ " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[13]\u001b[39m\u001b[32m, line 5\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mprint)('Ordered Statistics:')\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m unmatched ')'\n"
+ ]
+ }
+ ],
+ "source": [
+ "customer_set = {'book', 'hat', 'mug'}\n",
+ "product_orders = {'t-shirt': 4, 'mug': 9, 'hat': 6, 'book': 7, 'keychain': 8}\n",
+ "total_products_ordered = sum(product_orders.values())\n",
+ "\n",
+ "print)('Ordered Statistics:')\n",
+ "print(total_products_ordered)\n",
+ "print(sum(products_ordered.values)/total_products_ordered))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": "python-starter",
"language": "python",
- "name": "python3"
+ "name": "conda-env-python-starter"
},
"language_info": {
"codemirror_mode": {
@@ -68,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.13"
+ "version": "3.11.13"
}
},
"nbformat": 4,