From 5e3997ac746e72c4a28812fddadc9513324987c1 Mon Sep 17 00:00:00 2001 From: jannajulianfeiten Date: Thu, 4 Sep 2025 19:18:56 +0100 Subject: [PATCH 1/4] lab solved --- lab-python-functions.ipynb | 272 ++++++++++++++++++++++++++++++++++++- 1 file changed, 269 insertions(+), 3 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..87015e8 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,13 +43,279 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "40e1d6ad-fa61-43d2-84a5-b68844b7c778", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 180, + "id": "327bde1e-5ffe-4d17-93dc-207741327ea0", + "metadata": {}, + "outputs": [], + "source": [ + "# Define a function named initialize_inventory that takes products as a parameter. \n", + "#Inside the function, implement the code for initializing the inventory dictionary using a loop and user input.\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " \"\"\"Shows the number of each item\"\"\"\n", + " for item in products:\n", + " number_of_items = int(input(\"Number of \" + item + \": \")) \n", + " inventory[item] = number_of_items\n", + " print (inventory)\n", + " return inventory " + ] + }, + { + "cell_type": "code", + "execution_count": 168, + "id": "35135cb7-d43b-4537-b5ea-f0ba9d2a3bf6", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Number of t-shirt: 10\n", + "Number of mug: 10\n", + "Number of hat: 10\n", + "Number of book: 10\n", + "Number of keychain: 10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" + ] + }, + { + "data": { + "text/plain": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}" + ] + }, + "execution_count": 168, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "initialize_inventory(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 172, + "id": "7a2437ca-3681-49e0-8898-fe6f4067b1fd", + "metadata": {}, + "outputs": [], + "source": [ + "# Define a function named get_customer_orders that takes no parameters. \n", + "# Inside the function, implement the code for prompting the user to enter the product names using a loop. \n", + "# The function should return the customer_orders set.\n", + "\n", + "def get_customer_orders ():\n", + " customer_orders = set ()\n", + " answer = \"yes\"\n", + " while answer == \"yes\":\n", + " product = input(\"Choose a product: \")\n", + " customer_orders.add(product)\n", + " answer = input(\"Do you want something else? (yes/no): \").lower()\n", + " print (\"customer_ order\", customer_orders) " + ] + }, + { + "cell_type": "code", + "execution_count": 173, + "id": "d088eabd-adf4-4a04-a61e-fd3f4326ccd8", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Choose a product: book\n", + "Do you want something else? (yes/no): yes\n", + "Choose a product: hat\n", + "Do you want something else? (yes/no): no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "customer_ order {'book', 'hat'}\n" + ] + } + ], + "source": [ + "get_customer_orders ()" + ] + }, + { + "cell_type": "code", + "execution_count": 181, + "id": "86be53b5-2c9a-4f21-bd05-cccb95e47b6a", + "metadata": {}, + "outputs": [], + "source": [ + "#3. Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters. \n", + "# Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", + "\n", + "\n", + "def updated_inventory (customer_orders, inventory):\n", + " new_inventory = {}\n", + " for item in customer_orders:\n", + " if item in inventory:\n", + " inventory [item]-= 1\n", + " return inventory \n" + ] + }, + { + "cell_type": "code", + "execution_count": 182, + "id": "2c940a7e-9af8-4aa5-a9d3-86739c75f715", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 1, 'mug': 0, 'hat': 0, 'book': 0, 'keychain': 1}" + ] + }, + "execution_count": 182, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + " updated_inventory (customer_orders, inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 213, + "id": "941ac3fb-0f28-480c-bf8b-795e30f987b6", + "metadata": {}, + "outputs": [], + "source": [ + "# 4 Define a function named calculate_order_statistics that takes customer_orders and products as parameters. \n", + "#Inside the function, implement the code for calculating the order statistics \n", + "#(total products ordered, and percentage of unique products ordered). \n", + "#The function should return these values.\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total = len(customer_orders)\n", + " percentage = len(customer_orders) * 100 / len(products)\n", + " return total, percentage" + ] + }, + { + "cell_type": "code", + "execution_count": 212, + "id": "ad5111f1-f623-4dfb-ae9d-8015a30da88d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(4, 80.0)" + ] + }, + "execution_count": 212, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "calculate_order_statistics (customer_orders, products)" + ] + }, + { + "cell_type": "code", + "execution_count": 219, + "id": "8caaeaef-81c9-4dc4-98a0-dba2558dd29f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "80.0\n" + ] + } + ], + "source": [ + "# Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. \n", + "# Inside the function, implement the code for printing the order statistics.\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " total, percentage = order_statistics\n", + " print(total)\n", + " print(percentage)\n", + "\n", + "stats = calculate_order_statistics(customer_orders, products)\n", + "print(stats[0]) # total\n", + "print(stats[1]) # percentage \n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 222, + "id": "f1d59425-db7c-4b75-bf22-ab8ee0403f06", + "metadata": {}, + "outputs": [], + "source": [ + "# 6. Define a function named `print_updated_inventory` that takes `inventory` as a parameter. \n", + "#Inside the function, implement the code for printing the updated inventory.\n", + "\n", + "def print_updated_inventory (inventory):\n", + " print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 221, + "id": "0156e6a4-0983-4837-a047-b7554944e5ef", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 0, 'hat': 0, 'book': 0, 'keychain': 1}\n" + ] + } + ], + "source": [ + "print_updated_inventory (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0242022c-ead2-4c8c-94d5-ff986479ae10", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -61,7 +327,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 4a7884d1594939bbfafc3ffc6d1d770ec016fea8 Mon Sep 17 00:00:00 2001 From: jannajulianfeiten Date: Fri, 5 Sep 2025 13:52:59 +0100 Subject: [PATCH 2/4] solved lab --- lab-python-functions.ipynb | 156 +++++++++---------------------------- 1 file changed, 37 insertions(+), 119 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 87015e8..f712cdd 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "40e1d6ad-fa61-43d2-84a5-b68844b7c778", "metadata": {}, "outputs": [], @@ -56,12 +56,12 @@ }, { "cell_type": "code", - "execution_count": 180, + "execution_count": null, "id": "327bde1e-5ffe-4d17-93dc-207741327ea0", "metadata": {}, "outputs": [], "source": [ - "# Define a function named initialize_inventory that takes products as a parameter. \n", + "# 1 Define a function named initialize_inventory that takes products as a parameter. \n", "#Inside the function, implement the code for initializing the inventory dictionary using a loop and user input.\n", "def initialize_inventory(products):\n", " inventory = {}\n", @@ -75,95 +75,52 @@ }, { "cell_type": "code", - "execution_count": 168, + "execution_count": null, "id": "35135cb7-d43b-4537-b5ea-f0ba9d2a3bf6", "metadata": {}, - "outputs": [ - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Number of t-shirt: 10\n", - "Number of mug: 10\n", - "Number of hat: 10\n", - "Number of book: 10\n", - "Number of keychain: 10\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" - ] - }, - { - "data": { - "text/plain": [ - "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}" - ] - }, - "execution_count": 168, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "initialize_inventory(products)" + "inventory = initialize_inventory(products)\n", + "inventory" ] }, { "cell_type": "code", - "execution_count": 172, + "execution_count": null, "id": "7a2437ca-3681-49e0-8898-fe6f4067b1fd", "metadata": {}, "outputs": [], "source": [ - "# Define a function named get_customer_orders that takes no parameters. \n", + "# 2 Define a function named get_customer_orders that takes no parameters. \n", "# Inside the function, implement the code for prompting the user to enter the product names using a loop. \n", "# The function should return the customer_orders set.\n", "\n", - "def get_customer_orders ():\n", + "def get_customer_orders():\n", " customer_orders = set ()\n", " answer = \"yes\"\n", " while answer == \"yes\":\n", " product = input(\"Choose a product: \")\n", " customer_orders.add(product)\n", " answer = input(\"Do you want something else? (yes/no): \").lower()\n", - " print (\"customer_ order\", customer_orders) " + " while answer not in [\"yes\", \"no\"]:\n", + " answer = input(\"Do you want something else? (yes/no): \").lower()\n", + " print (\"customer_ order\", customer_orders) \n", + " return customer_orders" ] }, { "cell_type": "code", - "execution_count": 173, + "execution_count": null, "id": "d088eabd-adf4-4a04-a61e-fd3f4326ccd8", "metadata": {}, - "outputs": [ - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Choose a product: book\n", - "Do you want something else? (yes/no): yes\n", - "Choose a product: hat\n", - "Do you want something else? (yes/no): no\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "customer_ order {'book', 'hat'}\n" - ] - } - ], + "outputs": [], "source": [ - "get_customer_orders ()" + "customer_orders = get_customer_orders()" ] }, { "cell_type": "code", - "execution_count": 181, + "execution_count": null, "id": "86be53b5-2c9a-4f21-bd05-cccb95e47b6a", "metadata": {}, "outputs": [], @@ -171,39 +128,27 @@ "#3. Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters. \n", "# Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", "\n", - "\n", "def updated_inventory (customer_orders, inventory):\n", - " new_inventory = {}\n", " for item in customer_orders:\n", - " if item in inventory:\n", - " inventory [item]-= 1\n", + " if item in inventory and inventory[item] > 0:\n", + " inventory[item] -= 1\n", " return inventory \n" ] }, { "cell_type": "code", - "execution_count": 182, + "execution_count": null, "id": "2c940a7e-9af8-4aa5-a9d3-86739c75f715", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'t-shirt': 1, 'mug': 0, 'hat': 0, 'book': 0, 'keychain': 1}" - ] - }, - "execution_count": 182, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - " updated_inventory (customer_orders, inventory)" + "inventory = updated_inventory(customer_orders, inventory)\n", + "print(inventory)" ] }, { "cell_type": "code", - "execution_count": 213, + "execution_count": null, "id": "941ac3fb-0f28-480c-bf8b-795e30f987b6", "metadata": {}, "outputs": [], @@ -221,40 +166,21 @@ }, { "cell_type": "code", - "execution_count": 212, + "execution_count": null, "id": "ad5111f1-f623-4dfb-ae9d-8015a30da88d", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(4, 80.0)" - ] - }, - "execution_count": 212, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "calculate_order_statistics (customer_orders, products)" + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "print(order_statistics)" ] }, { "cell_type": "code", - "execution_count": 219, + "execution_count": null, "id": "8caaeaef-81c9-4dc4-98a0-dba2558dd29f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4\n", - "80.0\n" - ] - } - ], + "outputs": [], "source": [ "# Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. \n", "# Inside the function, implement the code for printing the order statistics.\n", @@ -265,14 +191,14 @@ " print(percentage)\n", "\n", "stats = calculate_order_statistics(customer_orders, products)\n", - "print(stats[0]) # total\n", - "print(stats[1]) # percentage \n", + "print(f\"Total customer products: {stats[0]}\") # total\n", + "print(f\"Percentage: {stats[1]}\") # percentage \n", " \n" ] }, { "cell_type": "code", - "execution_count": 222, + "execution_count": null, "id": "f1d59425-db7c-4b75-bf22-ab8ee0403f06", "metadata": {}, "outputs": [], @@ -280,24 +206,16 @@ "# 6. Define a function named `print_updated_inventory` that takes `inventory` as a parameter. \n", "#Inside the function, implement the code for printing the updated inventory.\n", "\n", - "def print_updated_inventory (inventory):\n", + "def print_updated_inventory(inventory):\n", " print(inventory)" ] }, { "cell_type": "code", - "execution_count": 221, + "execution_count": null, "id": "0156e6a4-0983-4837-a047-b7554944e5ef", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 1, 'mug': 0, 'hat': 0, 'book': 0, 'keychain': 1}\n" - ] - } - ], + "outputs": [], "source": [ "print_updated_inventory (inventory)" ] From 3dcd73ceadb88de22bb4c7098ca39b4fda903f39 Mon Sep 17 00:00:00 2001 From: jannajulianfeiten Date: Fri, 5 Sep 2025 13:58:19 +0100 Subject: [PATCH 3/4] lab solved_2 --- .../lab-python-functions-checkpoint.ipynb | 253 ++++++++++++++++++ anaconda_projects/db/project_filebrowser.db | Bin 0 -> 32768 bytes 2 files changed, 253 insertions(+) create mode 100644 .ipynb_checkpoints/lab-python-functions-checkpoint.ipynb create mode 100644 anaconda_projects/db/project_filebrowser.db diff --git a/.ipynb_checkpoints/lab-python-functions-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-functions-checkpoint.ipynb new file mode 100644 index 0000000..f712cdd --- /dev/null +++ b/.ipynb_checkpoints/lab-python-functions-checkpoint.ipynb @@ -0,0 +1,253 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", + "metadata": {}, + "source": [ + "# Lab | Functions" + ] + }, + { + "cell_type": "markdown", + "id": "0c581062-8967-4d93-b06e-62833222f930", + "metadata": { + "tags": [] + }, + "source": [ + "## Exercise: Managing Customer Orders with Functions\n", + "\n", + "In the previous exercise, you improved the code for managing customer orders by using loops and flow control. Now, let's take it a step further and refactor the code by introducing functions.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Define a function named `initialize_inventory` that takes `products` as a parameter. Inside the function, implement the code for initializing the inventory dictionary using a loop and user input.\n", + "\n", + "2. Define a function named `get_customer_orders` that takes no parameters. Inside the function, implement the code for prompting the user to enter the product names using a loop. The function should return the `customer_orders` set.\n", + "\n", + "3. Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters. Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", + "\n", + "4. Define a function named `calculate_order_statistics` that takes `customer_orders` and `products` as parameters. Inside the function, implement the code for calculating the order statistics (total products ordered, and percentage of unique products ordered). The function should return these values.\n", + "\n", + "5. Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. Inside the function, implement the code for printing the order statistics.\n", + "\n", + "6. Define a function named `print_updated_inventory` that takes `inventory` as a parameter. Inside the function, implement the code for printing the updated inventory.\n", + "\n", + "7. Call the functions in the appropriate sequence to execute the program and manage customer orders.\n", + "\n", + "Hints for functions:\n", + "\n", + "- Consider the input parameters required for each function and their return values.\n", + "- Utilize function parameters and return values to transfer data between functions.\n", + "- Test your functions individually to ensure they work correctly.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "40e1d6ad-fa61-43d2-84a5-b68844b7c778", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "327bde1e-5ffe-4d17-93dc-207741327ea0", + "metadata": {}, + "outputs": [], + "source": [ + "# 1 Define a function named initialize_inventory that takes products as a parameter. \n", + "#Inside the function, implement the code for initializing the inventory dictionary using a loop and user input.\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " \"\"\"Shows the number of each item\"\"\"\n", + " for item in products:\n", + " number_of_items = int(input(\"Number of \" + item + \": \")) \n", + " inventory[item] = number_of_items\n", + " print (inventory)\n", + " return inventory " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35135cb7-d43b-4537-b5ea-f0ba9d2a3bf6", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = initialize_inventory(products)\n", + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a2437ca-3681-49e0-8898-fe6f4067b1fd", + "metadata": {}, + "outputs": [], + "source": [ + "# 2 Define a function named get_customer_orders that takes no parameters. \n", + "# Inside the function, implement the code for prompting the user to enter the product names using a loop. \n", + "# The function should return the customer_orders set.\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set ()\n", + " answer = \"yes\"\n", + " while answer == \"yes\":\n", + " product = input(\"Choose a product: \")\n", + " customer_orders.add(product)\n", + " answer = input(\"Do you want something else? (yes/no): \").lower()\n", + " while answer not in [\"yes\", \"no\"]:\n", + " answer = input(\"Do you want something else? (yes/no): \").lower()\n", + " print (\"customer_ order\", customer_orders) \n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d088eabd-adf4-4a04-a61e-fd3f4326ccd8", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = get_customer_orders()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86be53b5-2c9a-4f21-bd05-cccb95e47b6a", + "metadata": {}, + "outputs": [], + "source": [ + "#3. Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters. \n", + "# Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", + "\n", + "def updated_inventory (customer_orders, inventory):\n", + " for item in customer_orders:\n", + " if item in inventory and inventory[item] > 0:\n", + " inventory[item] -= 1\n", + " return inventory \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c940a7e-9af8-4aa5-a9d3-86739c75f715", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = updated_inventory(customer_orders, inventory)\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "941ac3fb-0f28-480c-bf8b-795e30f987b6", + "metadata": {}, + "outputs": [], + "source": [ + "# 4 Define a function named calculate_order_statistics that takes customer_orders and products as parameters. \n", + "#Inside the function, implement the code for calculating the order statistics \n", + "#(total products ordered, and percentage of unique products ordered). \n", + "#The function should return these values.\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total = len(customer_orders)\n", + " percentage = len(customer_orders) * 100 / len(products)\n", + " return total, percentage" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ad5111f1-f623-4dfb-ae9d-8015a30da88d", + "metadata": {}, + "outputs": [], + "source": [ + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "print(order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8caaeaef-81c9-4dc4-98a0-dba2558dd29f", + "metadata": {}, + "outputs": [], + "source": [ + "# Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. \n", + "# Inside the function, implement the code for printing the order statistics.\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " total, percentage = order_statistics\n", + " print(total)\n", + " print(percentage)\n", + "\n", + "stats = calculate_order_statistics(customer_orders, products)\n", + "print(f\"Total customer products: {stats[0]}\") # total\n", + "print(f\"Percentage: {stats[1]}\") # percentage \n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f1d59425-db7c-4b75-bf22-ab8ee0403f06", + "metadata": {}, + "outputs": [], + "source": [ + "# 6. Define a function named `print_updated_inventory` that takes `inventory` as a parameter. \n", + "#Inside the function, implement the code for printing the updated inventory.\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0156e6a4-0983-4837-a047-b7554944e5ef", + "metadata": {}, + "outputs": [], + "source": [ + "print_updated_inventory (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0242022c-ead2-4c8c-94d5-ff986479ae10", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/anaconda_projects/db/project_filebrowser.db b/anaconda_projects/db/project_filebrowser.db new file mode 100644 index 0000000000000000000000000000000000000000..6fab372a6ef9c51ddfc1ae31aaead8212bd88eaf GIT binary patch literal 32768 zcmeI)PjAv-9Ki9GZT#Ch^u&qe$&zJ|EiPkDPN(nq#w(EghdT^=4@A$2cz$r_Dfk=yHHbF>gU>p_GA6G*3w#Y&Y}we z1Q0*~0R#|0009KR!@ znQ$87on9%t(kr5LWQtO?SlkiGM8o!MVH)qvpwj*9%KlZ&wL9{%(vVGi*!C>xj+}ni z?MT(j4%bZ#6#{Y{gAF{>2=G0hvds{tEjC0R!%TCRyTO-*YI9+$9 z8kx$(na&^`FHf`FVJFO_?0!BskwR11Ff)SH`&1WG2{bXDpA%0b(R6wHrkt1^Y;UGv z$!81J_KN0*n);*oKMDc}AbeFd^iM$m0R#|0009ILKmY** z5I_I{1Q0*~0R#|0009ILKmY**5I_Kd+b3=lv70R#|0009ILKmY** z5V%$#`2Roe|6fZ(BLWB@fB*srAb Date: Fri, 5 Sep 2025 14:12:50 +0100 Subject: [PATCH 4/4] lab_solved2 --- lab-python-functions.ipynb | 118 +++++++++++++++++++++++++++++++------ 1 file changed, 100 insertions(+), 18 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index f712cdd..37278e6 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "40e1d6ad-fa61-43d2-84a5-b68844b7c778", "metadata": {}, "outputs": [], @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "327bde1e-5ffe-4d17-93dc-207741327ea0", "metadata": {}, "outputs": [], @@ -75,10 +75,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "35135cb7-d43b-4537-b5ea-f0ba9d2a3bf6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Number of t-shirt: 10\n", + "Number of mug: 10\n", + "Number of hat: 10\n", + "Number of book: 10\n", + "Number of keychain: 10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" + ] + }, + { + "data": { + "text/plain": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "inventory = initialize_inventory(products)\n", "inventory" @@ -86,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "7a2437ca-3681-49e0-8898-fe6f4067b1fd", "metadata": {}, "outputs": [], @@ -110,17 +139,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "d088eabd-adf4-4a04-a61e-fd3f4326ccd8", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Choose a product: hat\n", + "Do you want something else? (yes/no): yes\n", + "Choose a product: hat\n", + "Do you want something else? (yes/no): yes\n", + "Choose a product: book\n", + "Do you want something else? (yes/no): no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "customer_ order {'book', 'hat'}\n" + ] + } + ], "source": [ "customer_orders = get_customer_orders()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "86be53b5-2c9a-4f21-bd05-cccb95e47b6a", "metadata": {}, "outputs": [], @@ -137,10 +186,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "2c940a7e-9af8-4aa5-a9d3-86739c75f715", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 9, 'book': 9, 'keychain': 10}\n" + ] + } + ], "source": [ "inventory = updated_inventory(customer_orders, inventory)\n", "print(inventory)" @@ -148,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "941ac3fb-0f28-480c-bf8b-795e30f987b6", "metadata": {}, "outputs": [], @@ -166,10 +223,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "ad5111f1-f623-4dfb-ae9d-8015a30da88d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 40.0)\n" + ] + } + ], "source": [ "order_statistics = calculate_order_statistics(customer_orders, products)\n", "print(order_statistics)" @@ -177,10 +242,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "id": "8caaeaef-81c9-4dc4-98a0-dba2558dd29f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total customer products: 2\n", + "Percentage: 40.0\n" + ] + } + ], "source": [ "# Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. \n", "# Inside the function, implement the code for printing the order statistics.\n", @@ -198,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "f1d59425-db7c-4b75-bf22-ab8ee0403f06", "metadata": {}, "outputs": [], @@ -212,10 +286,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "0156e6a4-0983-4837-a047-b7554944e5ef", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 9, 'book': 9, 'keychain': 10}\n" + ] + } + ], "source": [ "print_updated_inventory (inventory)" ]