diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..1e0840c 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,122 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "bd8c032d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:\n", + "- Total piece ordered: 4\n", + "- Percentage piece: 133.33\n", + "\n", + "Updated Inventory:\n", + "- t-shirt: 19\n", + "- mug: 19\n", + "- hat: 19\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\"]\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " for i in range(4):\n", + " order = input(f\"Enter the name of product {i+1} to order: \").lower()\n", + " customer_orders.add(order)\n", + " return customer_orders\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_piece_ordered = len(customer_orders)\n", + " percentage_piece = (total_piece_ordered / len(products)) * 100\n", + " return {\"total_piece_ordered\": total_piece_ordered, \"percentage_piece\": round(percentage_piece, 2)}\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " print(\"\\nOrder Statistics:\")\n", + " for key, value in order_statistics.items():\n", + " print(f\"- {key.replace('_', ' ').capitalize()}: {value}\")\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"\\nUpdated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"- {product}: {quantity}\")\n", + "\n", + "inventory = initialize_inventory(products)\n", + "customer_orders = get_customer_orders()\n", + "update_inventory(customer_orders, inventory)\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "print_order_statistics(order_statistics)\n", + "print_updated_inventory(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e1dfbef2", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " for i in range(3):\n", + " order = input(f\"Enter the name of product {i+1} to order: \")\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", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_ordered = len(customer_orders)\n", + " percentage_unique = (total_ordered / len(products)) * 100\n", + " return {\"total_ordered\": total_ordered, \"percentage_unique\": percentage_unique}\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " print(\"Order Statistics:\")\n", + " for k, v in order_statistics.items():\n", + " print(f\"{k}: {v}\")\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "data-analyst", "language": "python", "name": "python3" }, @@ -61,7 +172,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,