diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..446a60d 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,121 @@ "\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": 18, + "id": "82cf7574", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "cca67e2c", + "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": 20, + "id": "3f9207d8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 6, 'hat': 8, 'book': 10, 'keychain': 4}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "8eb27252", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "780cc294", + "metadata": {}, + "outputs": [], + "source": [ + "num_orders = int(input(\"How many products would you like to order? \"))\n", + "\n", + "for i in range(1, 4): # 1, 2, 3\n", + " order = input(f\"Enter name of product {i}: \")\n", + " customer_orders.add(order)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "fb61f1ed", + "metadata": {}, + "outputs": [], + "source": [ + "answer = \"yes\"\n", + "\n", + "while answer == \"yes\":\n", + " prod_name = input (\"please enter name of product: \")\n", + " customer_orders.add(prod_name)\n", + " answer = input(' do you want to continue (yes/no)')" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "6cf181e9", + "metadata": {}, + "outputs": [], + "source": [ + "for i in customer_orders : \n", + " if i in inventory :\n", + " inventory [i] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "fe026864", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 5, 'hat': 7, 'book': 9, 'keychain': 4}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +165,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,