diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..cdb842c 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,206 @@ "\n", "3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")." ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a7b01f32", + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\" CÓDIGO ORIGINAL \"\"\"\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(\"enter quantity of stock of \"))\n", + " inventory[product] = quantity\n", + "\n", + "print(inventory)\n", + "\n", + "customer_orders = set()\n", + "\n", + "order = input(\"add 3 products to your order\")\n", + "customer_orders.add(order)\n", + "\n", + "order = input(\"add 2 products to your order\")\n", + "customer_orders.add(order)\n", + "\n", + "order = input(\"add 3 products to your order\")\n", + "customer_orders.add(order)\n", + "\n", + "print(customer_orders)\n", + "\n", + "total_orders = len(customer_orders)\n", + "total_products = len(products)\n", + "\n", + "print(\"The number of orders is \", total_orders)\n", + "\n", + "percentage_products = ((total_orders / total_products) * 100)\n", + "\n", + "print(\"The percentage is \", percentage_products,\"%\")\n", + "\n", + "order_status = (total_orders, percentage_products)\n", + "\n", + "print(order_status)\n", + "\n", + "print(\"Order Statistics: \")\n", + "print(\"Total Products Ordered: \", total_orders)\n", + "print(\"Percentage of Products Ordered: \", int(percentage_products), \"%\")\n", + "\n", + "product_name = customer_orders.pop()\n", + "inventory[product_name] -=1\n", + "\n", + "product_name = customer_orders.pop()\n", + "inventory[product_name] -=1\n", + "\n", + "product_name = customer_orders.pop()\n", + "inventory[product_name] -=1\n", + "\n", + "print(\"Updated Inventory :\")\n", + "print(\"Inventory of t-shirts :\", inventory[\"t-shirt\"])\n", + "print(\"Inventory of mugs :\", inventory[\"mug\"])\n", + "print(\"Inventory of hats :\", inventory[\"hat\"])\n", + "print(\"Inventory of books :\", inventory[\"book\"])\n", + "print(\"Inventory of keychains :\", inventory[\"keychain\"])\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b05736ae", + "metadata": {}, + "outputs": [], + "source": [ + "#1 \n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(\"enter quantity of stock of \"))\n", + " inventory[product] = quantity\n", + "\n", + "print(inventory)\n", + "\n", + "costumer_orders = set()\n", + "\n", + "\n", + "for order in range(3):\n", + " order = input(\"Insert product to add to your order\")\n", + " costumer_orders.add(order)\n", + "\n", + "print(costumer_orders)\n", + "\n", + "total_orders = len(costumer_orders)\n", + "total_products = len(products)\n", + "\n", + "print(\"The number of orders is \", total_orders)\n", + "\n", + "percentage_products = ((total_orders / total_products) * 100)\n", + "\n", + "print(\"The percentage is \", percentage_products,\"%\")\n", + "\n", + "order_status = (total_orders, percentage_products)\n", + "\n", + "print(\"Order Statistics: \")\n", + "print(\"Total Products Ordered: \", total_orders)\n", + "print(\"Percentage of Products Ordered: \", int(percentage_products), \"%\")\n", + "\n", + "for name in costumer_orders:\n", + " inventory[name] -= 1\n", + "\n", + "print(\"Updated Inventory Report:\")\n", + "for item in inventory:\n", + " print(f\"Inventory of {item} : {inventory[item]}\")\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "fccb71d5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 15, 'mug': 15, 'hat': 15, 'book': 15, 'keychain': 15}\n", + "{'hat', 'mug', 'book'}\n", + "The number of orders is 3\n", + "The percentage is 60.0 %\n", + "Order Statistics: \n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60 %\n", + "Updated Inventory Report:\n", + "Inventory of t-shirt : 15\n", + "Inventory of mug : 14\n", + "Inventory of hat : 14\n", + "Inventory of book : 14\n", + "Inventory of keychain : 15\n" + ] + } + ], + "source": [ + "#2\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(\"enter quantity of stock of \"))\n", + " inventory[product] = quantity\n", + "\n", + "print(inventory)\n", + "\n", + "costumer_orders = set()\n", + "\n", + "order = input(\"Would you like to make an order? (Yes/No)\")\n", + "\n", + "if order != \"No\":\n", + " while order == \"Yes\":\n", + " order = input(\"Insert product to add to your order\")\n", + " costumer_orders.add(order)\n", + " order = input(\"Would you like to add another product? (Yes/No)\")\n", + "elif order != \"No\" and order != \"Yes\":\n", + " input(\"Invalid answer, please try again (Yes/No)\")\n", + "elif order == \"No\":\n", + " print(\"Thank you for your order\")\n", + "\n", + "print(costumer_orders)\n", + "\n", + "total_orders = len(costumer_orders)\n", + "total_products = len(products)\n", + "\n", + "print(\"The number of orders is \", total_orders)\n", + "\n", + "percentage_products = ((total_orders / total_products) * 100)\n", + "\n", + "print(\"The percentage is \", percentage_products,\"%\")\n", + "\n", + "order_status = (total_orders, percentage_products)\n", + "\n", + "print(\"Order Statistics: \")\n", + "print(\"Total Products Ordered: \", total_orders)\n", + "print(\"Percentage of Products Ordered: \", int(percentage_products), \"%\")\n", + "\n", + "for name in costumer_orders:\n", + " inventory[name] -= 1\n", + "\n", + "print(\"Updated Inventory Report:\")\n", + "for item in inventory:\n", + " print(f\"Inventory of {item} : {inventory[item]}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +250,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,