diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..0a10902 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,13 +43,224 @@ "\n", "\n" ] + }, + { + "cell_type": "markdown", + "id": "eeb73ced-a006-47eb-89e3-200bbe51f03f", + "metadata": {}, + "source": [ + "__Step 1:__" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "9b54565b-1826-4232-b4bf-033e0c20a57a", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " qty = int(input(f\"Enter inventory quantity for {product}: \"))\n", + " inventory[product] = qty\n", + " return inventory" + ] + }, + { + "cell_type": "markdown", + "id": "a11c8e1d-8c96-4236-bdba-f50a8fd2445c", + "metadata": {}, + "source": [ + "__Step 2:__" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "137017de-3fc2-428f-8ad1-906d6ec38691", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders(products):\n", + " customer_orders = set()\n", + " while True:\n", + " product = input(f\"Enter the name of a product to order ({products}): \").strip().lower()\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Product not found. Please enter a valid product name.\")\n", + " continue\n", + " another = input(\"Add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + " return customer_orders" + ] + }, + { + "cell_type": "markdown", + "id": "c37bc19c-166b-450f-88d3-bce944dc581d", + "metadata": {}, + "source": [ + "__Step 3:__" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "21a908a6-6ceb-46df-8ace-5488c1d00a1c", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " else:\n", + " print(f\"Warning: {product} is out of stock and can't be decremented.\")\n", + " return inventory\n" + ] + }, + { + "cell_type": "markdown", + "id": "36cdc507-f755-469c-b5ca-96d2fdbc5426", + "metadata": {}, + "source": [ + "__Step 4:__" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "980dfee4-c25b-45be-9e14-7b3098032128", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_ordered = (total_products_ordered / len(products)) * 100\n", + " return total_products_ordered, percentage_ordered" + ] + }, + { + "cell_type": "markdown", + "id": "e01a524c-31b3-4a0c-81d1-12167d78740f", + "metadata": {}, + "source": [ + "__Step 5:__" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "847a2999-e170-4b05-8f10-10dc8c739175", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " total_products, percent = order_statistics\n", + " print(\"\\nOrder Statistics:\")\n", + " print(f\"Total Products Ordered: {total_products}\")\n", + " print(f\"Percentage of Products Ordered: {percent:.2f}%\")" + ] + }, + { + "cell_type": "markdown", + "id": "ea5e442f-c21e-48a3-80fb-4b42f63840e2", + "metadata": {}, + "source": [ + "__Step 6:__" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "ccffb21d-ed9e-41ac-b392-01982d5ded98", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"\\nUpdated Inventory:\")\n", + " for product, qty in inventory.items():\n", + " print(f\"{product}: {qty}\")" + ] + }, + { + "cell_type": "markdown", + "id": "5ea3990a-1a88-44d7-86f5-87e0e08ee9a6", + "metadata": {}, + "source": [ + "__Step 7:__" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "3e3ae237-e248-481b-8a84-661d57586324", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter inventory quantity for t-shirt: 22\n", + "Enter inventory quantity for mug: 11\n", + "Enter inventory quantity for hat: 50\n", + "Enter inventory quantity for book: 90\n", + "Enter inventory quantity for keychain: 120\n", + "Enter the name of a product to order (['t-shirt', 'mug', 'hat', 'book', 'keychain']): mug\n", + "Add another product? (yes/no): yes\n", + "Enter the name of a product to order (['t-shirt', 'mug', 'hat', 'book', 'keychain']): book\n", + "Add another product? (yes/no): yes\n", + "Enter the name of a product to order (['t-shirt', 'mug', 'hat', 'book', 'keychain']): hat\n", + "Add another product? (yes/no): no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n", + "\n", + "Updated Inventory:\n", + "t-shirt: 22\n", + "mug: 10\n", + "hat: 49\n", + "book: 89\n", + "keychain: 120\n" + ] + } + ], + "source": [ + "def main():\n", + " products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + " inventory = initialize_inventory(products)\n", + " customer_orders = get_customer_orders(products)\n", + " inventory = 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)\n", + "\n", + "main()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "392a2fb4-e1f0-473a-a922-361ecd1fd1c4", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "ironhack", "language": "python", - "name": "python3" + "name": "ironhack" }, "language_info": { "codemirror_mode": { @@ -61,7 +272,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.7" } }, "nbformat": 4,