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..abcbe06f --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,136 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# empty inventory dict\n", + "inventory = {}\n", + "\n", + "# input quantity\n", + "print(\"Input quantity for each product:\")\n", + "for product in products:\n", + " quantity = int(input(f\"{product.capitalize()}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "# cuatomer orders\n", + "customer_orders = set()\n", + "\n", + "#User inputs three product names\n", + "print(\"\\nInput three products a customer wants to order:\")\n", + "for i in range(3):\n", + " while True:\n", + " order = input(f\"Product {i+1}: \").strip().lower()\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " break\n", + " else:\n", + " print(\"Product is not available. Please choose a different products.\")\n", + "\n", + "print(\"\\nCustomer Ordered Products:\")\n", + "for product in customer_orders:\n", + " print(product.capitalize())\n", + "\n", + "#Calculate order statistics\n", + "total_products_ordered = len(customer_orders)\n", + "total_products_available = len(products)\n", + "percentage_ordered = (total_products_ordered / total_products_available) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "# Update inventory by subtracting 1 from each ordered product\n", + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "\n", + "# Print updated inventory\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product.capitalize()}: {quantity}\")\n" + ] + }, + { + "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/.ipynb_checkpoints/labdatastructures.ipynb b/.ipynb_checkpoints/labdatastructures.ipynb new file mode 100644 index 00000000..1855e665 --- /dev/null +++ b/.ipynb_checkpoints/labdatastructures.ipynb @@ -0,0 +1,120 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "Lhs_fnl5DnqX", + "outputId": "24a44717-afa9-4cd0-8981-7050d25e4e04" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Input quantity for each product:\n", + "\n", + "Input three products a customer wants to order:\n", + "\n", + "Customer Ordered Products:\n", + "Keychain\n", + "Book\n", + "Hat\n", + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n", + "\n", + "Updated Inventory:\n", + "T-shirt: 100\n", + "Mug: 23\n", + "Hat: 46\n", + "Book: 22\n", + "Keychain: 41\n" + ] + } + ], + "source": [ + "# products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# empty inventory dict\n", + "inventory = {}\n", + "\n", + "# input quantity\n", + "print(\"Input quantity for each product:\")\n", + "for product in products:\n", + " quantity = int(input(f\"{product.capitalize()}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "# cuatomer orders\n", + "customer_orders = set()\n", + "\n", + "#User inputs three product names\n", + "print(\"\\nInput three products a customer wants to order:\")\n", + "for i in range(3):\n", + " while True:\n", + " order = input(f\"Product {i+1}: \").strip().lower()\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " break\n", + " else:\n", + " print(\"Product is not available. Please choose a different products.\")\n", + "\n", + "print(\"\\nCustomer Ordered Products:\")\n", + "for product in customer_orders:\n", + " print(product.capitalize())\n", + "\n", + "#Calculate order statistics\n", + "total_products_ordered = len(customer_orders)\n", + "total_products_available = len(products)\n", + "percentage_ordered = (total_products_ordered / total_products_available) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "# Update inventory by subtracting 1 from each ordered product\n", + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "\n", + "# Print updated inventory\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product.capitalize()}: {quantity}\")\n" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "base", + "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": 0 +}