diff --git a/Lab4.ipynb b/Lab4.ipynb new file mode 100644 index 0000000..18e7c92 --- /dev/null +++ b/Lab4.ipynb @@ -0,0 +1,367 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "512f6d15-6b7d-4608-9d3c-833bcf5eff95", + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "dffaee5d-89ba-4051-8de4-4159bd3f1e28", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert quantity of mug: 3\n", + "Insert quantity of chair: 4\n" + ] + } + ], + "source": [ + "products = [\"mug\", \"chair\"] # list ready\n", + "Inventory= {item:int(input(f\"Insert quantity of {item}: \")) for item in products}" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "69013be2-9139-4569-9268-b900c0248625", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'mug': 3, 'chair': 4}" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "7745617e-4b37-4e33-8d13-743b5e417d49", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert the inventory for chair? Currently at 4: 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Phone is not in the inventory.\n" + ] + } + ], + "source": [ + "c_orders= [\"chair\",\"Phone\"]\n", + "\n", + "update = { order : int(input(f\"Insert the inventory for {order}? Currently at {Inventory[order]}: \")) if order in Inventory else print(f\"{order} is not in the inventory.\") for order in c_orders} \n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "277f3efe-2ba3-454b-859b-b4ebfd1a1827", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'chair': 2, 'Phone': None}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "update" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "a04e26bb-4d2b-4974-9070-90962f885dcd", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert order: chair\n", + "Insert order: door\n", + "Insert order: phone\n" + ] + } + ], + "source": [ + "num_orders = 3\n", + "get_customer_order= [ input(\"Insert order: \") for x in range(num_orders)]\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "e02fe98d-5820-480d-946b-98887ca8344e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['chair', 'door', 'phone']" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_customer_order\n" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "0a2afb29-97ca-4f96-b53c-0fbd3f7c41e4", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert price for chair 3\n", + "Insert price for Phone 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n" + ] + } + ], + "source": [ + "c_orders= [\"chair\",\"Phone\"]\n", + "tot=0\n", + "for i in c_orders:\n", + " n=int(input(f\"Insert price for {i}\"))\n", + " tot=tot+n\n", + "\n", + "print(tot)\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "9f9e83b9-cad2-400d-a215-994355c25188", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert price for chair 10\n", + "Insert price for Phone 5\n" + ] + } + ], + "source": [ + "c_orders= [\"chair\",\"Phone\"]\n", + "\n", + "total_price= sum(int(input(f\"Insert price for {i}\")) for i in c_orders )" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "15a8028e-4ccf-4c13-82e4-cccf9648e933", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "15\n" + ] + } + ], + "source": [ + "print(total_price)" + ] + }, + { + "cell_type": "markdown", + "id": "ac2748ce-ce8f-4ebf-9209-e080a601c6c3", + "metadata": {}, + "source": [ + "def update_inventory(*customer_orders, **inventory):\n", + " for order in customer_orders:\n", + " if order in inventory:\n", + " # Prompt user for the new inventory value\n", + " new_stock = int(input(f\"Insert the inventory for {order}? Currently at {inventory[order]}: \"))\n", + " inventory[order] = new_stock # Update the inventory\n", + " else:\n", + " print(f\"{order} is not in the inventory.\")\n", + "\n", + "\n", + " \n", + " \n", + "\n", + " \n", + " compr = {k: v for k, v in inventory.items() if v != 0}\n", + " return compr\n", + "\n", + "new_inventory = update_inventory('apple', 'banana', 'cherry', apple=10, banana=5, cherry=0, orange=3)\n", + "print(new_inventory)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "de8d1b47-bd3f-4c65-b655-8459ffae39e9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "raw", + "id": "3b29f8fe-28fa-411a-a42e-8cb93a43cd18", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "c7f28a4d-0bfd-44cd-b5ea-fbac2096526e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'apple': 8, 'cherry': 3, 'orange': 3}\n" + ] + } + ], + "source": [ + "inventory = {'apple': 8, 'banana': , 'cherry': 3, 'orange': 3}\n", + "\n", + "# Create a dictionary comprehension to filter items with non-zero values\n", + "compr = {k: v for k, v in inventory.items() if v != 0}\n", + "\n", + "# Print the resulting filtered dictionary\n", + "print(compr) # Should output: {'apple': 8, 'banana': 8, 'cherry': 3, 'orange': 3}" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "f24bbb04-85e5-413f-90fe-83562ab41b74", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert the inventory for apple? Currently at 10: 5\n", + "Insert the inventory for banana? Currently at 5: 0\n", + "Insert the inventory for cherry? Currently at 0: 0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'apple': 5, 'orange': 3}\n" + ] + } + ], + "source": [ + "def update_inventory(*customer_orders, **inventory):\n", + " for order in customer_orders:\n", + " if order in inventory:\n", + " # Prompt user for the new inventory value\n", + " new_stock = int(input(f\"Insert the inventory for {order}? Currently at {inventory[order]}: \"))\n", + " inventory[order] = new_stock # Update the inventory\n", + " else:\n", + " print(f\"{order} is not in the inventory.\")\n", + "\n", + "\n", + " \n", + " \n", + "\n", + " \n", + " compr = {k: v for k, v in inventory.items() if v != 0}\n", + " return compr\n", + "\n", + "new_inventory = update_inventory('apple', 'banana', 'cherry', apple=10, banana=5, cherry=0, orange=3)\n", + "print(new_inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2d2c7e74-8dd7-43f0-8ecd-74d34126bce1", + "metadata": {}, + "outputs": [], + "source": [ + "c_orders= [\"chair\",\"Phone\"]\n", + "\n", + "total_price= sum(int(input(f\"Insert price for {i}\")) for i in c_orders )" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}