diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..cbe0e77 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,99 @@ "\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": "4f1b3dca", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book', 'mug', 'hat'}\n", + "Order Statistics:\n", + "Total products ordered: 3\n", + "Percentage of products ordered: 60.0 %\n", + "Updated inventory lis:\n", + "t-shirt : 2\n", + "mug : 3\n", + "hat : 5\n", + "book : 7\n", + "keychain : 10\n" + ] + } + ], + "source": [ + "# 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " inventory[product] = int(input(\"Cantidad de \" + product))\n", + "\n", + "customer_orders = set()\n", + "\n", + "for i in range(3):\n", + " order = input (\"type 3 products you like to order:\")\n", + " customer_orders.add(order)\n", + "print (customer_orders)\n", + "\n", + "total = len (customer_orders)\n", + "percentage = (total/len(products))*100\n", + "\n", + "print(\"Order Statistics:\")\n", + "print(\"Total products ordered:\", total)\n", + "print(\"Percentage of products ordered:\", percentage, \"%\")\n", + "\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory [product] -= 1\n", + "\n", + "print (\"Updated inventory lis:\")\n", + "\n", + "for product in inventory:\n", + " print (product, \":\", inventory [product])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "046bc5b1", + "metadata": {}, + "outputs": [], + "source": [ + "# 2\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " product = input(\"Enter a product to order: \")\n", + " customer_orders.add(product)\n", + "\n", + " more = input(\"Do you want to add another product? (yes/no): \")\n", + "\n", + " if more.lower() != \"yes\":\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "1060d54c", + "metadata": {}, + "outputs": [], + "source": [ + "# 3\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory [product] -= 1" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +143,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,