diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..d85a8814 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,88 @@ "\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": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {}\n", + "{'t-shirt': 10}\n", + "{'t-shirt': 10, 'mug': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n", + "Inventory: {'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n", + "50\n", + "Invalid product. Please choose from the available products.\n", + "Customer orders: {'mug', 'book', 'keychain'}\n", + "Order statistics:\n", + "Total products ordered: 3\n", + "Percentage of products ordered: 6.38%\n", + "t-shirt: 10 remaining\n", + "mug: 9 remaining\n", + "hat: 10 remaining\n", + "book: 9 remaining\n", + "keychain: 9 remaining\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "\n", + "print(\"Inventory:\", inventory)\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}:\"))\n", + " inventory[product] = quantity \n", + " inventory_total = sum(inventory.values()) \n", + " print(inventory) \n", + "print(\"Inventory:\", inventory)\n", + "customer_orders = set()\n", + "\n", + "print(inventory_total)\n", + "\n", + "while len(customer_orders) < 3:\n", + " order = input(\"Enter a product to order:\")\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " inventory_total -= 1\n", + " inventory[order] -= 1\n", + " else:\n", + " print(\"Invalid product. Please choose from the available products.\")\n", + "print(\"Customer orders:\", customer_orders)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "\n", + "\n", + "\n", + "\n", + "print(\"Order statistics:\")\n", + "print(\"Total products ordered:\", total_products_ordered)\n", + "percentage_ordered = (total_products_ordered / inventory_total) * 100\n", + "print(\"Percentage of products ordered:\", f\"{percentage_ordered:.2f}%\")\n", + "\n", + "for item, qty in inventory.items():\n", + " print(f\"{item}: {qty} remaining\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +145,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.3" } }, "nbformat": 4,