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..5b3ce9e0 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,76 @@ +{ + "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. " + ] + } + ], + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/.virtual_documents/lab-python-data-structures.ipynb b/.virtual_documents/lab-python-data-structures.ipynb new file mode 100644 index 00000000..31ce19d4 --- /dev/null +++ b/.virtual_documents/lab-python-data-structures.ipynb @@ -0,0 +1,108 @@ + + + + + + +# Step 1: Define the list of products +products = ["t-shirt", "mug", "hat", "book", "keychain"] +print(f"āœ… Products defined: {products}") + + +# Step 2: Create an empty inventory dictionary +inventory = {} +print("āœ… Empty inventory dictionary created.") + + +# Step 3: Input inventory quantity for each product +print("\n--- Inventory Setup ---") +for product in products: + while True: + try: + # Ask the user for the quantity of the current product + quantity = int(input(f"Enter the quantity available for '{product}': ")) + if quantity >= 0: + inventory[product] = quantity + break + else: + print("Quantity must be a non-negative integer.") + except ValueError: + print("Invalid input. Please enter a whole number.") + +print(f"\nšŸ“¦ Initial Inventory: {inventory}") + + +# Step 4: Create an empty set for customer orders +customer_orders = set() +print("āœ… Empty customer orders set created.") + + +# Step 5: Input three customer orders +print("\n--- Customer Orders ---") +products_lower = [p.lower() for p in products] # For case-insensitive validation +products_set = set(products) + +for i in range(1, 4): + while True: + order_input = input(f"Enter the name of product #{i} (options: {', '.join(products)}): ").lower() + # Check if the entered product is in the list (case-insensitive check) + if order_input in products_lower: + # Add the correctly cased product name (if found) to the set + # Find the original cased name from the list + correct_product_name = next(p for p in products if p.lower() == order_input) + customer_orders.add(correct_product_name) + break + else: + print(f"'{order_input}' is not a valid product. Please choose from the list.") + + +# Step 6: Print the products in the customer_orders set +print("\nšŸ›’ Products in Customer Orders Set:") +print(customer_orders) + + +# Step 7: Calculate Order Statistics +# The total number of unique products ordered is the size of the set +total_products_ordered = len(customer_orders) + + +# The total available unique products is the size of the initial products list +total_available_products = len(products) + + +# Calculate the percentage +# (Unique products ordered / Total unique products) * 100 +percentage_ordered = (total_products_ordered / total_available_products) * 100 + +# Store statistics in a tuple +order_status = (total_products_ordered, percentage_ordered) + +# Print the order statistics +print("\n--- Order Statistics ---") +print("Order Statistics:") +print(f"Total Products Ordered: {order_status[0]}") +print(f"Percentage of Products Ordered: {order_status[1]:.2f}%") # Format to 2 decimal places + + +# Step 8: Update the inventory +print("\n--- Updating Inventory ---") +# Subtract 1 from the quantity of each product in the customer_orders set +for product_name in customer_orders: + # Check if the product exists in the inventory and its quantity is > 0 + if product_name in inventory and inventory[product_name] > 0: + inventory[product_name] -= 1 + print(f"ā¬‡ļø Subtracted 1 from '{product_name}'.") + elif product_name in inventory and inventory[product_name] == 0: + print(f"āš ļø Warning: '{product_name}' was ordered but inventory is already 0. Inventory remains 0.") + else: + # This case should not happen if input validation is strict, but is good practice + print(f"Product '{product_name}' not found in inventory. Cannot update.") + + +# Step 9: Print the updated inventory +print("\nšŸ“ Updated Inventory:") +for product, quantity in inventory.items(): + print(f"{product}: {quantity}") + + + diff --git a/anaconda_projects/17e19d5e-eb24-4c27-9484-7f1e8d7c84b0/lab-python-data-structures.ipynb b/anaconda_projects/17e19d5e-eb24-4c27-9484-7f1e8d7c84b0/lab-python-data-structures.ipynb new file mode 100644 index 00000000..f3710955 --- /dev/null +++ b/anaconda_projects/17e19d5e-eb24-4c27-9484-7f1e8d7c84b0/lab-python-data-structures.ipynb @@ -0,0 +1 @@ +{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Lab | Data Structures ","metadata":{"tags":[]}},{"cell_type":"markdown","source":"## Exercise: Managing Customer Orders\n\nAs 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\nFollow the steps below to complete the exercise:\n\n1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n# Step 1: Define the list of products\nproducts = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\nprint(f\"Products defined: {products}\")\n2. Create an empty dictionary called `inventory`.\n\n3. 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\n4. Create an empty set called `customer_orders`.\n\n5. 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\n6. Print the products in the `customer_orders` set.\n\n7. 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\n8. Print the order statistics using the following format:\n ```\n Order Statistics:\n Total Products Ordered: \n Percentage of Products Ordered: % \n ```\n\n9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n\n10. Print the updated inventory, displaying the quantity of each product on separate lines.\n\nSolve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. ","metadata":{}},{"cell_type":"code","source":"# Step 1: Define the list of products\nproducts = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\nprint(f\"āœ… Products defined: {products}\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"āœ… Products defined: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n"}],"execution_count":1},{"cell_type":"code","source":"# Step 2: Create an empty inventory dictionary\ninventory = {}\nprint(\"āœ… Empty inventory dictionary created.\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"āœ… Empty inventory dictionary created.\n"}],"execution_count":2},{"cell_type":"code","source":"# Step 3: Input inventory quantity for each product\nprint(\"\\n--- Inventory Setup ---\")\nfor product in products:\n while True:\n try:\n # Ask the user for the quantity of the current product\n quantity = int(input(f\"Enter the quantity available for '{product}': \"))\n if quantity >= 0:\n inventory[product] = quantity\n break\n else:\n print(\"Quantity must be a non-negative integer.\")\n except ValueError:\n print(\"Invalid input. Please enter a whole number.\")\n\nprint(f\"\\nšŸ“¦ Initial Inventory: {inventory}\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\n--- Inventory Setup ---\n"},{"name":"stdin","output_type":"stream","text":"Enter the quantity available for 't-shirt': c\n"},{"name":"stdout","output_type":"stream","text":"Invalid input. Please enter a whole number.\n"},{"name":"stdin","output_type":"stream","text":"Enter the quantity available for 't-shirt': 5\nEnter the quantity available for 'mug': 6\nEnter the quantity available for 'hat': 7\nEnter the quantity available for 'book': 8\nEnter the quantity available for 'keychain': 9\n"},{"name":"stdout","output_type":"stream","text":"\nšŸ“¦ Initial Inventory: {'t-shirt': 5, 'mug': 6, 'hat': 7, 'book': 8, 'keychain': 9}\n"}],"execution_count":3},{"cell_type":"code","source":"# Step 4: Create an empty set for customer orders\ncustomer_orders = set()\nprint(\"āœ… Empty customer orders set created.\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"āœ… Empty customer orders set created.\n"}],"execution_count":4},{"cell_type":"code","source":"# Step 5: Input three customer orders\nprint(\"\\n--- Customer Orders ---\")\nproducts_lower = [p.lower() for p in products] # For case-insensitive validation\nproducts_set = set(products)\n\nfor i in range(1, 4):\n while True:\n order_input = input(f\"Enter the name of product #{i} (options: {', '.join(products)}): \").lower()\n # Check if the entered product is in the list (case-insensitive check)\n if order_input in products_lower:\n # Add the correctly cased product name (if found) to the set\n # Find the original cased name from the list\n correct_product_name = next(p for p in products if p.lower() == order_input)\n customer_orders.add(correct_product_name)\n break\n else:\n print(f\"'{order_input}' is not a valid product. Please choose from the list.\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\n--- Customer Orders ---\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): lion\n"},{"name":"stdout","output_type":"stream","text":"'lion' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): hourse\n"},{"name":"stdout","output_type":"stream","text":"'hourse' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): panda\n"},{"name":"stdout","output_type":"stream","text":"'panda' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): tiger\n"},{"name":"stdout","output_type":"stream","text":"'tiger' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): zebra\n"},{"name":"stdout","output_type":"stream","text":"'zebra' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): ziraf\n"},{"name":"stdout","output_type":"stream","text":"'ziraf' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): t-shirt\nEnter the name of product #2 (options: t-shirt, mug, hat, book, keychain): mug\nEnter the name of product #3 (options: t-shirt, mug, hat, book, keychain): hat\n"}],"execution_count":5},{"cell_type":"code","source":"# Step 6: Print the products in the customer_orders set\nprint(\"\\nšŸ›’ Products in Customer Orders Set:\")\nprint(customer_orders)","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\nšŸ›’ Products in Customer Orders Set:\n{'t-shirt', 'hat', 'mug'}\n"}],"execution_count":6},{"cell_type":"code","source":"# Step 7: Calculate Order Statistics\n# The total number of unique products ordered is the size of the set\ntotal_products_ordered = len(customer_orders)","metadata":{"trusted":true},"outputs":[],"execution_count":7},{"cell_type":"code","source":"# The total available unique products is the size of the initial products list\ntotal_available_products = len(products)","metadata":{"trusted":true},"outputs":[],"execution_count":8},{"cell_type":"code","source":"# Calculate the percentage\n# (Unique products ordered / Total unique products) * 100\npercentage_ordered = (total_products_ordered / total_available_products) * 100\n\n# Store statistics in a tuple\norder_status = (total_products_ordered, percentage_ordered)\n\n# Print the order statistics\nprint(\"\\n--- Order Statistics ---\")\nprint(\"Order Statistics:\")\nprint(f\"Total Products Ordered: {order_status[0]}\")\nprint(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\") # Format to 2 decimal places","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\n--- Order Statistics ---\nOrder Statistics:\nTotal Products Ordered: 3\nPercentage of Products Ordered: 60.00%\n"}],"execution_count":9},{"cell_type":"code","source":"# Step 8: Update the inventory\nprint(\"\\n--- Updating Inventory ---\")\n# Subtract 1 from the quantity of each product in the customer_orders set\nfor product_name in customer_orders:\n # Check if the product exists in the inventory and its quantity is > 0\n if product_name in inventory and inventory[product_name] > 0:\n inventory[product_name] -= 1\n print(f\"ā¬‡ļø Subtracted 1 from '{product_name}'.\")\n elif product_name in inventory and inventory[product_name] == 0:\n print(f\"āš ļø Warning: '{product_name}' was ordered but inventory is already 0. Inventory remains 0.\")\n else:\n # This case should not happen if input validation is strict, but is good practice\n print(f\"Product '{product_name}' not found in inventory. Cannot update.\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\n--- Updating Inventory ---\nā¬‡ļø Subtracted 1 from 't-shirt'.\nā¬‡ļø Subtracted 1 from 'hat'.\nā¬‡ļø Subtracted 1 from 'mug'.\n"}],"execution_count":10},{"cell_type":"code","source":"# Step 9: Print the updated inventory\nprint(\"\\nšŸ“ Updated Inventory:\")\nfor product, quantity in inventory.items():\n print(f\"{product}: {quantity}\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\nšŸ“ Updated Inventory:\nt-shirt: 4\nmug: 5\nhat: 6\nbook: 8\nkeychain: 9\n"}],"execution_count":11},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]} \ No newline at end of file diff --git a/anaconda_projects/17e19d5e-eb24-4c27-9484-7f1e8d7c84b0/lab-python-data-structures1.ipynb b/anaconda_projects/17e19d5e-eb24-4c27-9484-7f1e8d7c84b0/lab-python-data-structures1.ipynb new file mode 100644 index 00000000..f3710955 --- /dev/null +++ b/anaconda_projects/17e19d5e-eb24-4c27-9484-7f1e8d7c84b0/lab-python-data-structures1.ipynb @@ -0,0 +1 @@ +{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Lab | Data Structures ","metadata":{"tags":[]}},{"cell_type":"markdown","source":"## Exercise: Managing Customer Orders\n\nAs 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\nFollow the steps below to complete the exercise:\n\n1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n# Step 1: Define the list of products\nproducts = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\nprint(f\"Products defined: {products}\")\n2. Create an empty dictionary called `inventory`.\n\n3. 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\n4. Create an empty set called `customer_orders`.\n\n5. 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\n6. Print the products in the `customer_orders` set.\n\n7. 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\n8. Print the order statistics using the following format:\n ```\n Order Statistics:\n Total Products Ordered: \n Percentage of Products Ordered: % \n ```\n\n9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n\n10. Print the updated inventory, displaying the quantity of each product on separate lines.\n\nSolve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. ","metadata":{}},{"cell_type":"code","source":"# Step 1: Define the list of products\nproducts = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\nprint(f\"āœ… Products defined: {products}\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"āœ… Products defined: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n"}],"execution_count":1},{"cell_type":"code","source":"# Step 2: Create an empty inventory dictionary\ninventory = {}\nprint(\"āœ… Empty inventory dictionary created.\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"āœ… Empty inventory dictionary created.\n"}],"execution_count":2},{"cell_type":"code","source":"# Step 3: Input inventory quantity for each product\nprint(\"\\n--- Inventory Setup ---\")\nfor product in products:\n while True:\n try:\n # Ask the user for the quantity of the current product\n quantity = int(input(f\"Enter the quantity available for '{product}': \"))\n if quantity >= 0:\n inventory[product] = quantity\n break\n else:\n print(\"Quantity must be a non-negative integer.\")\n except ValueError:\n print(\"Invalid input. Please enter a whole number.\")\n\nprint(f\"\\nšŸ“¦ Initial Inventory: {inventory}\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\n--- Inventory Setup ---\n"},{"name":"stdin","output_type":"stream","text":"Enter the quantity available for 't-shirt': c\n"},{"name":"stdout","output_type":"stream","text":"Invalid input. Please enter a whole number.\n"},{"name":"stdin","output_type":"stream","text":"Enter the quantity available for 't-shirt': 5\nEnter the quantity available for 'mug': 6\nEnter the quantity available for 'hat': 7\nEnter the quantity available for 'book': 8\nEnter the quantity available for 'keychain': 9\n"},{"name":"stdout","output_type":"stream","text":"\nšŸ“¦ Initial Inventory: {'t-shirt': 5, 'mug': 6, 'hat': 7, 'book': 8, 'keychain': 9}\n"}],"execution_count":3},{"cell_type":"code","source":"# Step 4: Create an empty set for customer orders\ncustomer_orders = set()\nprint(\"āœ… Empty customer orders set created.\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"āœ… Empty customer orders set created.\n"}],"execution_count":4},{"cell_type":"code","source":"# Step 5: Input three customer orders\nprint(\"\\n--- Customer Orders ---\")\nproducts_lower = [p.lower() for p in products] # For case-insensitive validation\nproducts_set = set(products)\n\nfor i in range(1, 4):\n while True:\n order_input = input(f\"Enter the name of product #{i} (options: {', '.join(products)}): \").lower()\n # Check if the entered product is in the list (case-insensitive check)\n if order_input in products_lower:\n # Add the correctly cased product name (if found) to the set\n # Find the original cased name from the list\n correct_product_name = next(p for p in products if p.lower() == order_input)\n customer_orders.add(correct_product_name)\n break\n else:\n print(f\"'{order_input}' is not a valid product. Please choose from the list.\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\n--- Customer Orders ---\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): lion\n"},{"name":"stdout","output_type":"stream","text":"'lion' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): hourse\n"},{"name":"stdout","output_type":"stream","text":"'hourse' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): panda\n"},{"name":"stdout","output_type":"stream","text":"'panda' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): tiger\n"},{"name":"stdout","output_type":"stream","text":"'tiger' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): zebra\n"},{"name":"stdout","output_type":"stream","text":"'zebra' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): ziraf\n"},{"name":"stdout","output_type":"stream","text":"'ziraf' is not a valid product. Please choose from the list.\n"},{"name":"stdin","output_type":"stream","text":"Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): t-shirt\nEnter the name of product #2 (options: t-shirt, mug, hat, book, keychain): mug\nEnter the name of product #3 (options: t-shirt, mug, hat, book, keychain): hat\n"}],"execution_count":5},{"cell_type":"code","source":"# Step 6: Print the products in the customer_orders set\nprint(\"\\nšŸ›’ Products in Customer Orders Set:\")\nprint(customer_orders)","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\nšŸ›’ Products in Customer Orders Set:\n{'t-shirt', 'hat', 'mug'}\n"}],"execution_count":6},{"cell_type":"code","source":"# Step 7: Calculate Order Statistics\n# The total number of unique products ordered is the size of the set\ntotal_products_ordered = len(customer_orders)","metadata":{"trusted":true},"outputs":[],"execution_count":7},{"cell_type":"code","source":"# The total available unique products is the size of the initial products list\ntotal_available_products = len(products)","metadata":{"trusted":true},"outputs":[],"execution_count":8},{"cell_type":"code","source":"# Calculate the percentage\n# (Unique products ordered / Total unique products) * 100\npercentage_ordered = (total_products_ordered / total_available_products) * 100\n\n# Store statistics in a tuple\norder_status = (total_products_ordered, percentage_ordered)\n\n# Print the order statistics\nprint(\"\\n--- Order Statistics ---\")\nprint(\"Order Statistics:\")\nprint(f\"Total Products Ordered: {order_status[0]}\")\nprint(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\") # Format to 2 decimal places","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\n--- Order Statistics ---\nOrder Statistics:\nTotal Products Ordered: 3\nPercentage of Products Ordered: 60.00%\n"}],"execution_count":9},{"cell_type":"code","source":"# Step 8: Update the inventory\nprint(\"\\n--- Updating Inventory ---\")\n# Subtract 1 from the quantity of each product in the customer_orders set\nfor product_name in customer_orders:\n # Check if the product exists in the inventory and its quantity is > 0\n if product_name in inventory and inventory[product_name] > 0:\n inventory[product_name] -= 1\n print(f\"ā¬‡ļø Subtracted 1 from '{product_name}'.\")\n elif product_name in inventory and inventory[product_name] == 0:\n print(f\"āš ļø Warning: '{product_name}' was ordered but inventory is already 0. Inventory remains 0.\")\n else:\n # This case should not happen if input validation is strict, but is good practice\n print(f\"Product '{product_name}' not found in inventory. Cannot update.\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\n--- Updating Inventory ---\nā¬‡ļø Subtracted 1 from 't-shirt'.\nā¬‡ļø Subtracted 1 from 'hat'.\nā¬‡ļø Subtracted 1 from 'mug'.\n"}],"execution_count":10},{"cell_type":"code","source":"# Step 9: Print the updated inventory\nprint(\"\\nšŸ“ Updated Inventory:\")\nfor product, quantity in inventory.items():\n print(f\"{product}: {quantity}\")","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"\nšŸ“ Updated Inventory:\nt-shirt: 4\nmug: 5\nhat: 6\nbook: 8\nkeychain: 9\n"}],"execution_count":11},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]} \ No newline at end of file diff --git a/anaconda_projects/db/project_filebrowser.db b/anaconda_projects/db/project_filebrowser.db new file mode 100644 index 00000000..d694e81d Binary files /dev/null and b/anaconda_projects/db/project_filebrowser.db differ diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..80139836 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -20,7 +20,9 @@ "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", + "# Step 1: Define the list of products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(f\"Products defined: {products}\")\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", @@ -50,13 +52,403 @@ "\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": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "āœ… Products defined: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "# Step 1: Define the list of products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(f\"āœ… Products defined: {products}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "āœ… Empty inventory dictionary created.\n" + ] + } + ], + "source": [ + "# Step 2: Create an empty inventory dictionary\n", + "inventory = {}\n", + "print(\"āœ… Empty inventory dictionary created.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Inventory Setup ---\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity available for 't-shirt': c\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid input. Please enter a whole number.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity available for 't-shirt': 5\n", + "Enter the quantity available for 'mug': 6\n", + "Enter the quantity available for 'hat': 7\n", + "Enter the quantity available for 'book': 8\n", + "Enter the quantity available for 'keychain': 9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "šŸ“¦ Initial Inventory: {'t-shirt': 5, 'mug': 6, 'hat': 7, 'book': 8, 'keychain': 9}\n" + ] + } + ], + "source": [ + "# Step 3: Input inventory quantity for each product\n", + "print(\"\\n--- Inventory Setup ---\")\n", + "for product in products:\n", + " while True:\n", + " try:\n", + " # Ask the user for the quantity of the current product\n", + " quantity = int(input(f\"Enter the quantity available for '{product}': \"))\n", + " if quantity >= 0:\n", + " inventory[product] = quantity\n", + " break\n", + " else:\n", + " print(\"Quantity must be a non-negative integer.\")\n", + " except ValueError:\n", + " print(\"Invalid input. Please enter a whole number.\")\n", + "\n", + "print(f\"\\nšŸ“¦ Initial Inventory: {inventory}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "āœ… Empty customer orders set created.\n" + ] + } + ], + "source": [ + "# Step 4: Create an empty set for customer orders\n", + "customer_orders = set()\n", + "print(\"āœ… Empty customer orders set created.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Customer Orders ---\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): lion\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'lion' is not a valid product. Please choose from the list.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): hourse\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'hourse' is not a valid product. Please choose from the list.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): panda\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'panda' is not a valid product. Please choose from the list.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): tiger\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'tiger' is not a valid product. Please choose from the list.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): zebra\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'zebra' is not a valid product. Please choose from the list.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): ziraf\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'ziraf' is not a valid product. Please choose from the list.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of product #1 (options: t-shirt, mug, hat, book, keychain): t-shirt\n", + "Enter the name of product #2 (options: t-shirt, mug, hat, book, keychain): mug\n", + "Enter the name of product #3 (options: t-shirt, mug, hat, book, keychain): hat\n" + ] + } + ], + "source": [ + "# Step 5: Input three customer orders\n", + "print(\"\\n--- Customer Orders ---\")\n", + "products_lower = [p.lower() for p in products] # For case-insensitive validation\n", + "products_set = set(products)\n", + "\n", + "for i in range(1, 4):\n", + " while True:\n", + " order_input = input(f\"Enter the name of product #{i} (options: {', '.join(products)}): \").lower()\n", + " # Check if the entered product is in the list (case-insensitive check)\n", + " if order_input in products_lower:\n", + " # Add the correctly cased product name (if found) to the set\n", + " # Find the original cased name from the list\n", + " correct_product_name = next(p for p in products if p.lower() == order_input)\n", + " customer_orders.add(correct_product_name)\n", + " break\n", + " else:\n", + " print(f\"'{order_input}' is not a valid product. Please choose from the list.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "šŸ›’ Products in Customer Orders Set:\n", + "{'t-shirt', 'hat', 'mug'}\n" + ] + } + ], + "source": [ + "# Step 6: Print the products in the customer_orders set\n", + "print(\"\\nšŸ›’ Products in Customer Orders Set:\")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 7: Calculate Order Statistics\n", + "# The total number of unique products ordered is the size of the set\n", + "total_products_ordered = len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# The total available unique products is the size of the initial products list\n", + "total_available_products = len(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Order Statistics ---\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n" + ] + } + ], + "source": [ + "# Calculate the percentage\n", + "# (Unique products ordered / Total unique products) * 100\n", + "percentage_ordered = (total_products_ordered / total_available_products) * 100\n", + "\n", + "# Store statistics in a tuple\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "# Print the order statistics\n", + "print(\"\\n--- Order Statistics ---\")\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\") # Format to 2 decimal places" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Updating Inventory ---\n", + "ā¬‡ļø Subtracted 1 from 't-shirt'.\n", + "ā¬‡ļø Subtracted 1 from 'hat'.\n", + "ā¬‡ļø Subtracted 1 from 'mug'.\n" + ] + } + ], + "source": [ + "# Step 8: Update the inventory\n", + "print(\"\\n--- Updating Inventory ---\")\n", + "# Subtract 1 from the quantity of each product in the customer_orders set\n", + "for product_name in customer_orders:\n", + " # Check if the product exists in the inventory and its quantity is > 0\n", + " if product_name in inventory and inventory[product_name] > 0:\n", + " inventory[product_name] -= 1\n", + " print(f\"ā¬‡ļø Subtracted 1 from '{product_name}'.\")\n", + " elif product_name in inventory and inventory[product_name] == 0:\n", + " print(f\"āš ļø Warning: '{product_name}' was ordered but inventory is already 0. Inventory remains 0.\")\n", + " else:\n", + " # This case should not happen if input validation is strict, but is good practice\n", + " print(f\"Product '{product_name}' not found in inventory. Cannot update.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "šŸ“ Updated Inventory:\n", + "t-shirt: 4\n", + "mug: 5\n", + "hat: 6\n", + "book: 8\n", + "keychain: 9\n" + ] + } + ], + "source": [ + "# Step 9: Print the updated inventory\n", + "print(\"\\nšŸ“ Updated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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": { @@ -68,7 +460,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,