diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..bff20d1 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,136 @@ "\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": 1, + "id": "927bdee9", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "83ac8269", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "f29beb58", + "metadata": {}, + "outputs": [], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"Enter quantity for {product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "83e81a4e", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "50c20d75", + "metadata": {}, + "outputs": [], + "source": [ + "while True:\n", + " order = input(\"enter the name of a product the customer wants : \"). lower()\n", + "\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"that product does not exist in the store.\") \n", + " \n", + " another = input(\"do you want to order another product? (yes/no) : \"). lower()\n", + "\n", + " if another == \"no\":\n", + " break " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "3b9eca2f", + "metadata": {}, + "outputs": [], + "source": [ + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " else:\n", + " print(f\"{product} is out of stock.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "4fef393f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "customer_orders:\n", + "mug\n", + "book\n", + "t-shirt\n" + ] + } + ], + "source": [ + "print(\"customer_orders:\")\n", + "for product in customer_orders:\n", + " print(product)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "bc20abbf", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "inventory:\n", + "t-shirt: 9\n", + "mug: 7\n", + "hat: 6\n", + "book: 11\n", + "keychain: 4\n" + ] + } + ], + "source": [ + "print(\"inventory:\")\n", + "for product in inventory:\n", + " print(f\"{product}: {inventory[product]}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +180,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,