diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..d9e47949 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,13 +50,85 @@ "\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": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter stock for article t-shirt 1\n", + "Please enter stock for article mug 2\n", + "Please enter stock for article hat 3\n", + "Please enter stock for article book 4\n", + "Please enter stock for article keychain 5\n", + "Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 1\n", + "Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 2\n", + "Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'hat', 'book'}\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n", + "The stock for t-shirt is 1\n", + "The stock for mug is 1\n", + "The stock for hat is 2\n", + "The stock for book is 3\n", + "The stock for keychain is 5\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " stock = int(input(f\"Please enter stock for article {product}\"))\n", + " inventory[product] = stock\n", + "\n", + "customer_orders = set()\n", + "\n", + "for purchase in range(3):\n", + " customer_orders.add(products[int(input(\"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain\"))])\n", + "\n", + "print(customer_orders)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (len(customer_orders)/len(inventory.values()))*100\n", + "\n", + "print(f\"\"\"Order Statistics:\n", + "Total Products Ordered: {total_products_ordered}\n", + "Percentage of Products Ordered: {percentage_ordered} %\"\"\")\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "for product in products:\n", + " print(\"The stock for\", product, \"is\", inventory[product])\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -68,7 +140,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,