Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions flow_controls.ipynb
Original file line number Diff line number Diff line change
@@ -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
}