diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..2443717 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,231 @@ "\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": 37, + "id": "864a3b47", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "products" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "e92bc4d2", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "8b60ba4d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 3, 'mug': 3, 'hat': 3, 'book': 3, 'keychain': 3}\n" + ] + } + ], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"How many {product} are in stock\"))\n", + " inventory[product] = quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "1efed2ae", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7f405e47", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'hat'}\n", + "{'t-shirt': 3, 'mug': 2, 'hat': 2, 'book': 3, 'keychain': 3}\n" + ] + } + ], + "source": [ + "#THIS CELL IS THIS LAB (the rest are from the previous lab)\n", + "\n", + "while True:\n", + "\n", + " while True:\n", + " order = input(\"Enter product name\")\n", + "\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " break\n", + " else:\n", + " print(\"invalid value\")\n", + "\n", + " while True:\n", + " another_order = input(\"Would you like to add another product (yes/no)?\")\n", + " if another_order == \"no\" or another_order == \"yes\":\n", + " break\n", + " else:\n", + " print('invalid answer. please enter \"yes\" or \"no\"')\n", + "\n", + " if another_order == \"no\":\n", + " break\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -=1\n", + "\n", + "print(customer_orders)\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "cfb58b2f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "total_products_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "101f9a06", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "40.0" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "procentage_ordered = len(customer_orders) / len (products) * 100\n", + "procentage_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "d7eab1c4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 40.0)" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_status = (total_products_ordered, procentage_ordered)\n", + "order_status" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "ca8f8583", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 40.0 %\n" + ] + } + ], + "source": [ + "print(f\"\"\"Order Statistics:\n", + "Total Products Ordered: {total_products_ordered}\n", + "Percentage of Products Ordered: {procentage_ordered} %\"\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "6ed8371e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt 3\n", + "mug 2\n", + "hat 2\n", + "book 3\n", + "keychain 3\n" + ] + } + ], + "source": [ + "for product in inventory:\n", + " print(product, inventory[product])" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +275,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,