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..f78ffbab --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,87 @@ +{ + "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. \n", + "\n", + "\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "customer_orders = ()\n", + "\n", + "user_input = input(\"\")\n", + "\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" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..1f09b5d0 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -48,15 +48,118 @@ "\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. " + "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Step 1:\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "#Step 2:\n", + "\n", + "inventory = {}\n", + "\n", + "#Step 3:\n", + "\n", + "#First, I'm asking the user to input the quantity for each item available in the list and storing it into a variable:\n", + "\n", + "tshirt_items_number = int(input(\"How many t-shirts are there in the inventory?\"))\n", + "\n", + "mug_items_number = int(input(\"How many mugs are there in the inventory?\"))\n", + "\n", + "hat_items_number = int(input(\"How many mugs are there in the inventory?\"))\n", + "\n", + "book_items_number = int(input(\"How many mugs are there in the inventory?\"))\n", + "\n", + "keychain_items_number = int(input(\"How many mugs are there in the inventory?\"))\n", + "\n", + "#now, I'll assign each quantity to the corresponding item, where the item is the key and the item number is the value\n", + "\n", + "inventory[\"t-shirt\"] = tshirt_items_number #dict[key] = value\n", + "\n", + "inventory[\"mug\"] = mug_items_number\n", + "\n", + "inventory[\"hat\"] = hat_items_number\n", + "\n", + "inventory[\"book\"] = book_items_number\n", + "\n", + "inventory[\"keychain\"] = keychain_items_number\n", + "\n", + "\n", + "#Step 4:\n", + "\n", + "customer_orders = set()\n", + "\n", + "#Step 5:\n", + "\n", + "order_1 = input(\"What is the first product your customer wants to order from the available ones?\")\n", + "\n", + "order_2 = input(\"What is the second product your customer wants to order from the available ones?\")\n", + "\n", + "order_3 = input(\"What is the third product your customer wants to order from the available ones?\")\n", + "\n", + "\n", + "customer_orders.add(order_1) #adding the first input as a single string\n", + "\n", + "customer_orders.add(order_2) #adding the second input as a single string\n", + "\n", + "customer_orders.add(order_3) #adding the third input as a single string\n", + "\n", + "#Step 6:\n", + "\n", + "print(customer_orders)\n", + "\n", + "#Step 7:\n", + "\n", + "total_products_ordered = int(len(customer_orders)) #counts number of items within the set\n", + "\n", + "percentage_ordered = int((total_products_ordered*100)/int(len(products))) #calculates the percentage of items purchased over the total number contained in our original list\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered) #tuple containing the info above\n", + "\n", + "\n", + "#Step 8\n", + "\n", + "\n", + "print(f\"\"\"```\\nOrder Statistics:\\nTotal Products Ordered: {total_products_ordered}\\nPercentage of Products Ordered: {percentage_ordered}%\\n```\"\"\")\n", + "\n", + "#Step 9\n", + "\n", + "#updating each value in the dictionary by subtracting 1 from current value: value = (current) value - 1\n", + "\n", + "inventory[\"t-shirt\"] = int(inventory[\"t-shirt\"] - 1)\n", + "\n", + "inventory[\"mug\"] = int(inventory[\"mug\"] - 1)\n", + "\n", + "inventory[\"hat\"] = int(inventory[\"hat\"] - 1)\n", + "\n", + "inventory[\"book\"] = int(inventory[\"book\"] - 1)\n", + "\n", + "inventory[\"keychain\"] = int(inventory[\"keychain\"] - 1)\n", + "\n", + "\n", + "#Step 10:\n", + "\n", + "print(\"Updated Inventory:\\n\"\n", + " f\"t-shirt: {inventory['t-shirt']}\\n\" #using \\n to go to the next line after each key value pair\n", + " f\"mug: {inventory['mug']}\\n\"\n", + " f\"hat: {inventory['hat']}\\n\"\n", + " f\"book: {inventory['book']}\\n\"\n", + " f\"keychain: {inventory['keychain']}\")" ] } ], "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 +171,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,