From 5c6fa09bcd25f5c7b28795fb82645999b9b79847 Mon Sep 17 00:00:00 2001 From: Ayoola Soremekun Date: Mon, 3 Nov 2025 00:01:50 +0100 Subject: [PATCH] Create flow_controls.ipynb --- flow_controls.ipynb | 121 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 flow_controls.ipynb diff --git a/flow_controls.ipynb b/flow_controls.ipynb new file mode 100644 index 0000000..66ccb9e --- /dev/null +++ b/flow_controls.ipynb @@ -0,0 +1,121 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "Lhs_fnl5DnqX", + "outputId": "b775d0b2-c9cd-4970-bab7-2f903c4a8f80" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Input quantity for each product:\n", + "T-shirt: 3\n", + "Mug: 4\n", + "Hat: 2\n", + "Book: 5\n", + "Keychain: 3\n", + "\n", + "Enter the name of a product a customer wants to order:Mug\n", + "'mug'added to order.\n", + "Do you want to add another product? (yes/no)no\n", + "\n", + "Customer Ordered Products:\n", + "Mug\n", + "\n", + "Order Statistics:\n", + "Total Products Ordered: 1\n", + "Percentage of Products Ordered: 20.00%\n", + "\n", + "Updated Inventory:\n", + "T-shirt: 3\n", + "Mug: 3\n", + "Hat: 2\n", + "Book: 5\n", + "Keychain: 3\n" + ] + } + ], + "source": [ + "#products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "# input quantity\n", + "print(\"Input quantity for each product:\")\n", + "for product in products:\n", + " quantity = int(input(f\"{product.capitalize()}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "# empty set for cuatomer orders\n", + "customer_orders = set()\n", + "\n", + "# customer order input loop\n", + "while True:\n", + " order = input(\"\\nEnter the name of a product a customer wants to order:\").strip().lower()\n", + "\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " print(f\"'{order}'added to order.\")\n", + " else:\n", + " print(\" Product not available. Please choose a different product.\")\n", + " continue\n", + "\n", + " another = input(\"Do you want to add another product? (yes/no)\").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "#customer order display\n", + "print(\"\\nCustomer Ordered Products:\")\n", + "for product in customer_orders:\n", + " print(product.capitalize())\n", + "56\n", + "\n", + "#Calculate order statistics\n", + "total_products_ordered = len(customer_orders)\n", + "total_products_available = len(products)\n", + "percentage_ordered = (total_products_ordered / total_products_available) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "\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", + "\n", + "# Update inventory from each ordered product\n", + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " else:\n", + " print(f\"'{product}' is out of stock\")\n", + "\n", + "# Display updated inventory\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product.capitalize()}: {quantity}\")\n" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file