diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..4831696b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,299 @@ "\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": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity of t-shirt: 50\n", + "Enter the quantity of mug: 60\n", + "Enter the quantity of hat: 100\n", + "Enter the quantity of book: 200\n", + "Enter the quantity of keychain: 400\n", + "Enter an ordered product: 30\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid product. Please choose from: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter an ordered product: t-shirt\n", + "Enter an ordered product: hat\n", + "Enter an ordered product: book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Customer Orders:\n", + "hat\n", + "t-shirt\n", + "book\n", + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n", + "\n", + "Updated Inventory:\n", + "t-shirt : 49\n", + "mug : 60\n", + "hat : 99\n", + "book : 199\n", + "keychain : 400\n" + ] + } + ], + "source": [ + "# Create the product list\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Create an empty inventory dictionary\n", + "inventory = {}\n", + "\n", + "# Ask for the quantity of every product\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "# Create an empty set for customer orders\n", + "customer_orders = set()\n", + "\n", + "# Continue asking until three valid products are entered\n", + "while len(customer_orders) < 3:\n", + " order = input(\n", + " \"Enter an ordered product: \"\n", + " ).strip().lower()\n", + "\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"Invalid product. Please choose from:\", products)\n", + "\n", + "# Display the customer orders\n", + "print(\"\\nCustomer Orders:\")\n", + "for product in customer_orders:\n", + " print(product)\n", + "\n", + "# Calculate the order statistics\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (\n", + " total_products_ordered / len(products)\n", + ") * 100\n", + "\n", + "# Store the statistics in a tuple\n", + "order_status = (\n", + " total_products_ordered,\n", + " percentage_ordered\n", + ")\n", + "\n", + "# Display the order statistics\n", + "print(\"\\nOrder Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")\n", + "\n", + "# Subtract one from each ordered product\n", + "for product in customer_orders:\n", + " inventory[product] = inventory[product] - 1\n", + "\n", + "# Display the updated inventory\n", + "print(\"\\nUpdated Inventory:\")\n", + "\n", + "for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity of t-shirt: 400\n", + "Enter the quantity of mug: 500\n", + "Enter the quantity of hat: 300\n", + "Enter the quantity of book: 600\n", + "Enter the quantity of keychain: 200\n" + ] + } + ], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the first product ordered: t-shirt\n", + "Enter the second product ordered: keychain\n", + "Enter the third product ordered: mug\n" + ] + } + ], + "source": [ + "order1 = input(\"Enter the first product ordered: \")\n", + "order2 = input(\"Enter the second product ordered: \")\n", + "order3 = input(\"Enter the third product ordered: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders.update([order1, order2, order3])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer Orders: {'keychain', 'mug', 't-shirt'}\n" + ] + } + ], + "source": [ + "print(\"Customer Orders:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "\n", + "percentage_ordered = (\n", + " total_products_ordered / len(products)\n", + ") * 100\n", + "\n", + "order_status = (\n", + " total_products_ordered,\n", + " percentage_ordered\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n" + ] + } + ], + "source": [ + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "for product in customer_orders:\n", + " inventory[product] = inventory[product] - 1" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory:\n", + "t-shirt : 399\n", + "mug : 499\n", + "hat : 300\n", + "book : 600\n", + "keychain : 199\n" + ] + } + ], + "source": [ + "print(\"Updated Inventory:\")\n", + "\n", + "for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +361,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.14" } }, "nbformat": 4,