diff --git a/Lab_Flow_control_exrcise.ipynb b/Lab_Flow_control_exrcise.ipynb new file mode 100644 index 0000000..d5c9e5a --- /dev/null +++ b/Lab_Flow_control_exrcise.ipynb @@ -0,0 +1,224 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "52c20051-b2c9-4c32-bbc9-cd8d1c76285e", + "metadata": {}, + "outputs": [], + "source": [ + "# Step 1: Define product list\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9fd8ef66-2483-4003-813a-190d7425cd04", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter quantity for t-shirt: 3\n", + "Enter quantity for mug: 3\n", + "Enter quantity for hat: 4\n", + "Enter quantity for book: 3\n", + "Enter quantity for keychain: 4\n" + ] + } + ], + "source": [ + "# Step 2: Create inventory dictionary\n", + "inventory = {}\n", + "for product in products:\n", + " inventory[product] = int(input(f\"Enter quantity for {product}: \"))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "6d8abfce-d760-47da-a699-4337f68f9b15", + "metadata": {}, + "outputs": [], + "source": [ + "# Step 3: Create empty set for customer orders\n", + "customer_orders = set()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "600123b1-fefe-4687-8c3d-3eda70dbc209", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a product to order: mug\n", + "Do you want to add another product? (yes/no): no\n" + ] + } + ], + "source": [ + "# Step 4: Loop to input products until user stops\n", + "while True:\n", + " order = input(\"Enter a product to order: \").lower()\n", + " \n", + " if order not in products:\n", + " print(\"Invalid product. Choose from the available products.\")\n", + " continue\n", + " \n", + " if order in customer_orders:\n", + " print(\"You already added this product.\")\n", + " else:\n", + " customer_orders.add(order)\n", + " \n", + " more = input(\"Do you want to add another product? (yes/no): \").lower()\n", + " if more != \"yes\":\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "a3852185-318f-4471-a5d2-18c478d3c21a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Customer Orders:\n", + "mug\n" + ] + } + ], + "source": [ + "# Step 5: Print customer orders\n", + "print(\"\\nCustomer Orders:\")\n", + "for item in customer_orders:\n", + " print(item)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a8bcf426-6ddd-42c3-94c9-70c465f73e0d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:\n", + "Total Products Ordered: 1\n", + "Percentage of Products Ordered: 20.00%\n" + ] + } + ], + "source": [ + "# Step 6: Calculate order statistics\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "e18fffa7-d988-4b7c-af93-3228901ff694", + "metadata": {}, + "outputs": [], + "source": [ + "# Step 7: Update inventory only for ordered products\n", + "for item in customer_orders:\n", + " if inventory[item] > 0:\n", + " inventory[item] -= 1\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "671523af-45d7-4913-8f32-eeaa298d6802", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Updated Inventory:\n", + "t-shirt: 3\n", + "mug: 2\n", + "hat: 4\n", + "book: 3\n", + "keychain: 4\n" + ] + } + ], + "source": [ + "# Step 8: Print updated inventory\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, qty in inventory.items():\n", + " print(f\"{product}: {qty}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "7fd81327-a794-417b-b17f-403ff50e6ac0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "C:\\Users\\kyila\n" + ] + } + ], + "source": [ + "import os\n", + "print(os.getcwd())\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3dbce055-0e42-401b-8ed2-2e3d5e6eddac", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}