diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..e8c6a13 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,100 @@ "\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": 2, + "id": "fefa9890", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b370f26", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "inventory = {}\n", + "for product in products:\n", + " inventory[product] = int(input(\"Enter the quantity of the product: \"))\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "ba3165d1", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()\n", + "\n", + "for customer_order in products:\n", + " customer_order = input(\"Which product would you like to order? \")\n", + " customer_orders.add(customer_order)\n", + "\n", + " extra_orders = input(\"Would you like to order another product? (yes/no) \").lower()\n", + " if extra_orders != 'yes':\n", + " break\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "466f8d26", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "8d848302", + "metadata": {}, + "outputs": [], + "source": [ + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + "#prueba" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7af7cfc7", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +144,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,