diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..59d061a 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,187 @@ "\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": 11, + "id": "be666ab6", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {} # empty dictionary" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "2bacc7d8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 6, 'mug': 4, 'hat': 8, 'book': 5, 'keychain': 7}\n" + ] + } + ], + "source": [ + "inventory[products[0]] = int(input(\"Enter the amount of t-shirts: \"))\n", + "inventory[products[1]] = int(input(\"Enter the amount of mugs: \"))\n", + "inventory[products[2]] = int(input(\"Enter the amount of hats: \"))\n", + "inventory[products[3]] = int(input(\"Enter the amount of books: \"))\n", + "inventory[products[4]] = int(input(\"Enter the amount of keychains: \"))\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d5088d9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your order: {'hat', 'book', 't-shirt'}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "customer_orders = set() # empty set\n", + "add_more = 'yes' # adding a condition for the loop\n", + "while add_more == 'yes':\n", + " product = input(\"Enter the product you want to order: \")\n", + " if product not in products:\n", + " print(\"product not found, try again\") # added repetition till the product is chosen from the list\n", + " else:\n", + " customer_orders.add(product) \n", + " add_more = input(\"Do you want to order more: yes/no ?\")\n", + "print(\"Your order: \", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "5f7aeafb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "5\n", + "60.0\n" + ] + } + ], + "source": [ + "products_ordered = len(customer_orders)\n", + "print(products_ordered)\n", + "\n", + "avaliable_products = len(products)\n", + "print(avaliable_products)\n", + "\n", + "percentage = (products_ordered/avaliable_products)*100\n", + "print(percentage)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "034b1461", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order status: ('ordered products:', 3, 'products avaliable:', 5)\n" + ] + } + ], + "source": [ + "order_status = (\"ordered products:\", products_ordered, \"products avaliable:\", avaliable_products)\n", + "print(\"Order status: \", order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "b66a9227", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 6, 'mug': 4, 'hat': 8, 'book': 5, 'keychain': 7}\n", + "{'hat', 'book', 't-shirt'}\n", + "dict_keys(['t-shirt', 'mug', 'hat', 'book', 'keychain'])\n" + ] + } + ], + "source": [ + "print(inventory)\n", + "print(customer_orders)\n", + "print(inventory.keys())" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "413deea2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 4, 'hat': 7, 'book': 4, 'keychain': 7}\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "ecb4141c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated inventory:\n", + "t-shirt: 5\n", + "mug: 4\n", + "hat: 7\n", + "book: 4\n", + "keychain: 7\n" + ] + } + ], + "source": [ + "print(\"Updated inventory:\")\n", + "for position, amount in inventory.items():\n", + " print(position + \": \" + str(amount))" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +231,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,