diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..848fbdb 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,73 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6f3ab339", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + " print(\"Initialize Inventory:\")\n", + " for product in products:\n", + " quantity = int(input(f\"Enter quantity available for '{product}': \"))\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " print(\"\\nEnter customer orders (type 'done' to finish):\")\n", + " while True:\n", + " order = input(\"Enter product name: \").strip().lower()\n", + " if order == 'done':\n", + " break\n", + " customer_orders.add(order)\n", + " return customer_orders\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for order in customer_orders:\n", + " if order in inventory and inventory[order] > 0:\n", + " inventory[order] -= 1\n", + " elif order in inventory:\n", + " print(f\"'{order}' is out of stock.\")\n", + " else:\n", + " print(f\"'{order}' is not available in the inventory.\")\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_ordered = len(customer_orders)\n", + " unique_ordered = len([item for item in customer_orders if item in products])\n", + " percentage_unique = (unique_ordered / len(products)) * 100\n", + " return total_ordered, percentage_unique\n", + "\n", + "def print_order_statistics(order_stats):\n", + " total_ordered, percentage_unique = order_stats\n", + " print(\"\\nOrder Statistics:\")\n", + " print(f\"- Total products ordered: {total_ordered}\")\n", + " print(f\"- Percentage of unique products ordered: {percentage_unique:.2f}%\")\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"\\nUpdated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"- {product}: {quantity} left\")\n", + "\n", + "# Main program logic\n", + "products = ['apple', 'banana', 'orange', 'grapes', 'mango']\n", + "\n", + "inventory = initialize_inventory(products)\n", + "customer_orders = get_customer_orders()\n", + "update_inventory(customer_orders, inventory)\n", + "order_stats = calculate_order_statistics(customer_orders, products)\n", + "print_order_statistics(order_stats)\n", + "print_updated_inventory(inventory)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +123,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,