diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..b1d981c8 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,200 @@ "\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": [], + "source": [ + "# 1.\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# 2.\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity for t-shirt: 6\n", + "Enter the quantity for mug: 5\n", + "Enter the quantity for hat: 6\n", + "Enter the quantity for book: 5\n", + "Enter the quantity for keychain: 6\n" + ] + } + ], + "source": [ + "# 3.\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "# 4.\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Available products: , t-shirt mug hat book keychain\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter product 1 to order: t-shirt\n", + "Enter product 2 to order: mug\n", + "Enter product 3 to order: book\n" + ] + } + ], + "source": [ + "# 5.\n", + "print(\"Available products:\", \", \", \" \".join(products))\n", + "while len(customer_orders) < 3:\n", + " order = input(f\"Enter product {len(customer_orders) + 1} to order: \").lower()\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"Invalid product. Please choose from the available products.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 't-shirt', 'book'}\n" + ] + } + ], + "source": [ + "# 6.\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "# 7.1.\n", + "total_products_ordered = len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "# 7.2.\n", + "total_products_ordered = len(customer_orders)\n", + "total_available_products = len(products)\n", + "\n", + "percentage_ordered = (total_products_ordered / total_available_products) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n" + ] + } + ], + "source": [ + "# 8.\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "# 9.\n", + "for item in customer_orders:\n", + " if item in inventory and inventory[item] > 0:\n", + " inventory[item] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory:\n", + "t-shirt: 5\n", + "mug: 4\n", + "hat: 6\n", + "book: 4\n", + "keychain: 6\n" + ] + } + ], + "source": [ + "# 10.\n", + "print(\"Updated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] } ], "metadata": { @@ -68,7 +262,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.5" } }, "nbformat": 4,