From e654695982198de58c6be8623468513027ec7555 Mon Sep 17 00:00:00 2001 From: ghazal-hassanzadeh Date: Tue, 7 Oct 2025 15:20:52 +0200 Subject: [PATCH 1/3] week1-Lab1 --- lab-python-data-structures.ipynb | 191 ++++++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..b07d3e31 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,198 @@ "\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": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "# step 1: Defining the list # list\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "print(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "# step 2: creating an empty dictionary # dictionary\n", + "\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "# step 3: Asking the user to enter the quantity of each product available in the inventory # for loop\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Please enter the quantity of {products}: \"))\n", + " inventory[product] = quantity # In the dictionary inventory, create (or update) an entry where the key is product and the value is quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# step 4: creating an empty set # set()\n", + "\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book', 'hat', 't-shirt', 'book,', 'keychain', 'mug'}\n" + ] + } + ], + "source": [ + "# step 5: Asking user to enter the name of 3 products that they want to order\n", + "\n", + "for i in range(3):\n", + " order = input(f\"Please enter product {i+1} that you want to order. Attention! Please choose from {products} list: \")\n", + " customer_orders.add(order)\n", + "\n", + "# Step 6: Printing products in the set \n", + "\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "source": [ + "#Step 7: Calculate total products ordered\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "print(total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "120.0\n" + ] + } + ], + "source": [ + "percentage_of_ordered_products = (total_products_ordered / len(products)) * 100\n", + "print(percentage_of_ordered_products)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 6\n", + "Percentage of Products Ordered: 120.0%\n" + ] + } + ], + "source": [ + "# Step 8: Prining the statistics\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_of_ordered_products}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 9: Updating Inventory\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated inventory is: \n", + "t-shirt: -2\n", + "mug: -1\n", + "hat: 0\n", + "book: 1\n", + "keychain: 2\n" + ] + } + ], + "source": [ + "# Step 10: Print the updated Inventory\n", + "print(\"Updated inventory is: \")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +255,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 189729db684eaeedf95456d03e1527bd3a3647a8 Mon Sep 17 00:00:00 2001 From: Ghazal Hassanzadeh Date: Wed, 19 Nov 2025 11:38:24 +0100 Subject: [PATCH 2/3] Solved lab --- lab-python-data-structures.ipynb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index b07d3e31..e8f19a1b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -51,6 +51,13 @@ "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": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -241,7 +248,7 @@ ], "metadata": { "kernelspec": { - "display_name": "base", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, From 5549bd4cecd964c1e4118ff84cc84591b853c655 Mon Sep 17 00:00:00 2001 From: Ghazal Hassanzadeh Date: Thu, 20 Nov 2025 11:10:39 +0100 Subject: [PATCH 3/3] Solved lab --- ...ab-python-data-structures-checkpoint.ipynb | 270 ++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 .ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb diff --git a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb new file mode 100644 index 00000000..e8f19a1b --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,270 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise: Managing Customer Orders\n", + "\n", + "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "\n", + "2. Create an empty dictionary called `inventory`.\n", + "\n", + "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", + "\n", + "4. Create an empty set called `customer_orders`.\n", + "\n", + "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", + "\n", + "6. Print the products in the `customer_orders` set.\n", + "\n", + "7. Calculate the following order statistics:\n", + " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", + " \n", + " Store these statistics in a tuple called `order_status`.\n", + "\n", + "8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % \n", + " ```\n", + "\n", + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "\n", + "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "\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": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "# step 1: Defining the list # list\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "print(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "# step 2: creating an empty dictionary # dictionary\n", + "\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "# step 3: Asking the user to enter the quantity of each product available in the inventory # for loop\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Please enter the quantity of {products}: \"))\n", + " inventory[product] = quantity # In the dictionary inventory, create (or update) an entry where the key is product and the value is quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# step 4: creating an empty set # set()\n", + "\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book', 'hat', 't-shirt', 'book,', 'keychain', 'mug'}\n" + ] + } + ], + "source": [ + "# step 5: Asking user to enter the name of 3 products that they want to order\n", + "\n", + "for i in range(3):\n", + " order = input(f\"Please enter product {i+1} that you want to order. Attention! Please choose from {products} list: \")\n", + " customer_orders.add(order)\n", + "\n", + "# Step 6: Printing products in the set \n", + "\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "source": [ + "#Step 7: Calculate total products ordered\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "print(total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "120.0\n" + ] + } + ], + "source": [ + "percentage_of_ordered_products = (total_products_ordered / len(products)) * 100\n", + "print(percentage_of_ordered_products)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 6\n", + "Percentage of Products Ordered: 120.0%\n" + ] + } + ], + "source": [ + "# Step 8: Prining the statistics\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_of_ordered_products}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 9: Updating Inventory\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated inventory is: \n", + "t-shirt: -2\n", + "mug: -1\n", + "hat: 0\n", + "book: 1\n", + "keychain: 2\n" + ] + } + ], + "source": [ + "# Step 10: Print the updated Inventory\n", + "print(\"Updated inventory is: \")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + } + ], + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}