diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..c99fce25 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,208 @@ "\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": 5, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "select quantity of available product: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "t-shirt: 10\n", + "mug: 10\n", + "hat: 10\n", + "book: 10\n", + "keychain: 10\n" + ] + } + ], + "source": [ + "print(\"select quantity of available product: \")\n", + "for product in products:\n", + " quantity = int(input(f\"{product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "select 3 products that the client wants to order: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Product: t-shirt\n", + "Product: mug\n", + "Product: book\n" + ] + } + ], + "source": [ + "print(\"select 3 products that the client wants to order: \")\n", + "for i in range(3):\n", + " order = input(f\"Product: \")\n", + " if order in products:\n", + " customer_orders.add(order)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "customer_orders:\n", + "{'mug', 'book', 't-shirt'}\n" + ] + } + ], + "source": [ + "print(\"\\ncustomer_orders:\")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 9, 'mug': 9, 'hat': 10, 'book': 9, 'keychain': 10}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_available = sum(inventory.values())\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / total_products_available) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 6%\n" + ] + } + ], + "source": [ + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_ordered:.0f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Updated Inventory:\n", + "t-shirt: 9\n", + "mug: 9\n", + "hat: 10\n", + "book: 9\n", + "keychain: 10\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "print(\"\\nUpdated Inventory:\")\n", + "for item, quantity in inventory.items():\n", + " print(f\"{item}: {quantity}\")" + ] } ], "metadata": { @@ -68,7 +270,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,