diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..6fc5785 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,379 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "74210aad", + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: ''", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mValueError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 7\u001b[39m\n\u001b[32m 4\u001b[39m inventory = {}\n\u001b[32m 6\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m product \u001b[38;5;129;01min\u001b[39;00m products:\n\u001b[32m----> \u001b[39m\u001b[32m7\u001b[39m quantity = \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43menter quantity of stock of \u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 8\u001b[39m inventory[product] = quantity\n\u001b[32m 10\u001b[39m \u001b[38;5;28mprint\u001b[39m(inventory)\n", + "\u001b[31mValueError\u001b[39m: invalid literal for int() with base 10: ''" + ] + } + ], + "source": [ + "\"\"\" ORIGINAL CODE \"\"\"\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(\"enter quantity of stock of \"))\n", + " inventory[product] = quantity\n", + "\n", + "print(inventory)\n", + "\n", + "costumer_orders = set()\n", + "\n", + "order = input(\"Would you like to make an order? (Yes/No)\")\n", + "\n", + "if order != \"No\":\n", + " while order == \"Yes\":\n", + " order = input(\"Insert product to add to your order\")\n", + " costumer_orders.add(order)\n", + " order = input(\"Would you like to add another product? (Yes/No)\")\n", + "elif order != \"No\" and order != \"Yes\":\n", + " input(\"Invalid answer, please try again (Yes/No)\")\n", + "elif order == \"No\":\n", + " print(\"Thank you for your order\")\n", + "\n", + "print(costumer_orders)\n", + "\n", + "total_orders = len(costumer_orders)\n", + "total_products = len(products)\n", + "\n", + "print(\"The number of orders is \", total_orders)\n", + "\n", + "percentage_products = ((total_orders / total_products) * 100)\n", + "\n", + "print(\"The percentage is \", percentage_products,\"%\")\n", + "\n", + "order_status = (total_orders, percentage_products)\n", + "\n", + "print(\"Order Statistics: \")\n", + "print(\"Total Products Ordered: \", total_orders)\n", + "print(\"Percentage of Products Ordered: \", int(percentage_products), \"%\")\n", + "\n", + "for name in costumer_orders:\n", + " inventory[name] -= 1\n", + "\n", + "print(\"Updated Inventory Report:\")\n", + "for item in inventory:\n", + " print(f\"Inventory of {item} : {inventory[item]}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b0aad067", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 20, 'mug': 20, 'hat': 20, 'book': 20, 'keychain': 20}\n" + ] + } + ], + "source": [ + "\"\"\" 1 \"\"\"\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "costumer_orders = set()\n", + "\n", + "def initialize_inv(products):\n", + " \"\"\" It will prompt a inventory initializer, where you will have to enter the initial quantities for the items in {products}\"\"\"\n", + " for product in products:\n", + " quantity = int(input(f\"Insert the quantity of {product}\"))\n", + " inventory[product] = quantity\n", + " return print(inventory)\n", + "\n", + "initialize_inv(products)\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "1bae7581", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thank you for ordering {'hat', 'mug'}\n" + ] + } + ], + "source": [ + "\"\"\"2\"\"\"\n", + "\n", + "\n", + "\n", + "def get_costumer_orders():\n", + " \"\"\"It will ask for if you want to make an order and if positive answer it will ask which producty until the user decides to stop\"\"\"\n", + " order = input(\"Would you like to make an order? (Yes/No)\")\n", + " \n", + " if order != \"No\":\n", + " while order == \"Yes\":\n", + " order = input(\"Insert product to add to your order\")\n", + " costumer_orders.add(order)\n", + " order = input(\"Would you like to add another product? (Yes/No)\")\n", + " elif order != \"No\" and order != \"Yes\":\n", + " input(\"Invalid answer, please try again (Yes/No)\")\n", + "\n", + " \n", + " return print(f\"Thank you for ordering {costumer_orders}\")\n", + "\n", + "get_costumer_orders()\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "7656cd16", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 20, 'mug': 20, 'hat': 20, 'book': 20, 'keychain': 20}\n" + ] + } + ], + "source": [ + "\"\"\"3\"\"\"\n", + "\n", + "\n", + "def update_inventory(costumer_orders, inventory):\n", + " \"\"\"It will update the inventory based on the costumer orders\"\"\"\n", + " for name in costumer_orders:\n", + " inventory[name] -= 1\n", + " return print(inventory)\n", + "\n", + "update_inventory(costumer_orders, inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "640d68cd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 40.0)" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"4\"\"\"\n", + "\n", + "def calculate_order_statistics(costumer_orders, products):\n", + " total_orders = len(costumer_orders)\n", + " unique_products = len(products)\n", + " total_unique = (total_orders / unique_products) * 100\n", + "\n", + " return total_orders, total_unique\n", + "\n", + "calculate_order_statistics(costumer_orders, products)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "ed7ead0e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 40%\n" + ] + }, + { + "data": { + "text/plain": [ + "(2, 40.0)" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"5\"\"\"\n", + "def print_order_statistics(order_statistics):\n", + " total_orders, total_unique = order_statistics\n", + " print(\"Order Statistics:\")\n", + " print(f\"Total Products Ordered: {total_orders}\")\n", + " print(f\"Percentage of Products Ordered: {int(total_unique)}%\")\n", + " return order_statistics\n", + "\n", + "print_order_statistics(order_statistics)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "b6bdf3ea", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory Report:\n", + "Inventory of t-shirt : 20\n", + "Inventory of mug : 20\n", + "Inventory of hat : 20\n", + "Inventory of book : 20\n", + "Inventory of keychain : 20\n" + ] + }, + { + "data": { + "text/plain": [ + "{'t-shirt': 20, 'mug': 20, 'hat': 20, 'book': 20, 'keychain': 20}" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"6\"\"\"\n", + "\n", + "def print_updated_inventory(inventory):\n", + " \"\"\"It will print the updated inventory report\"\"\"\n", + " print(\"Updated Inventory Report:\")\n", + " for item in inventory:\n", + " print(f\"Inventory of {item} : {inventory[item]}\")\n", + " return inventory\n", + "\n", + "print_updated_inventory(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "8cb86719", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thank you for ordering {'hat', 'mug'}\n", + "Order Statistics:\n", + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 40%\n", + "Updated Inventory Report:\n", + "Inventory of t-shirt : 30\n", + "Inventory of mug : 29\n", + "Inventory of hat : 29\n", + "Inventory of book : 30\n", + "Inventory of keychain : 30\n" + ] + } + ], + "source": [ + "\"\"\"7\"\"\"\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "costumer_orders = set()\n", + "\n", + "def initialize_inv(products):\n", + " \"\"\" It will prompt a inventory initializer, where you will have to enter the initial quantities for the items in {products}\"\"\"\n", + " for product in products:\n", + " quantity = int(input(f\"Insert the quantity of {product}\"))\n", + " inventory[product] = quantity\n", + " return print(inventory)\n", + "\n", + "initialize_inv(products)\n", + "\n", + "def get_costumer_orders():\n", + " \"\"\"It will ask for if you want to make an order and if positive answer it will ask which producty until the user decides to stop\"\"\"\n", + " order = input(\"Would you like to make an order? (Yes/No)\")\n", + " \n", + " if order != \"No\":\n", + " while order == \"Yes\":\n", + " order = input(\"Insert product to add to your order\")\n", + " costumer_orders.add(order)\n", + " order = input(\"Would you like to add another product? (Yes/No)\")\n", + " elif order != \"No\" and order != \"Yes\":\n", + " input(\"Invalid answer, please try again (Yes/No)\")\n", + "\n", + " \n", + " return print(f\"Thank you for ordering {costumer_orders}\")\n", + "\n", + "get_costumer_orders()\n", + "\n", + "def update_inventory(costumer_orders, inventory):\n", + " \"\"\"It will update the inventory based on the costumer orders\"\"\"\n", + " for name in costumer_orders:\n", + " inventory[name] -= 1\n", + " \n", + "update_inventory(costumer_orders, inventory)\n", + "\n", + "def calculate_order_statistics(costumer_orders, products):\n", + " total_orders = len(costumer_orders)\n", + " unique_products = len(products)\n", + " total_unique = (total_orders / unique_products) * 100\n", + "\n", + " return total_orders, total_unique\n", + "\n", + "calculate_order_statistics(costumer_orders, products)\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " total_orders, total_unique = order_statistics\n", + " print(\"Order Statistics:\")\n", + " print(f\"Total Products Ordered: {total_orders}\")\n", + " print(f\"Percentage of Products Ordered: {int(total_unique)}%\")\n", + " return order_statistics\n", + "\n", + "print_order_statistics(order_statistics)\n", + "\n", + "def print_updated_inventory(inventory):\n", + " \"\"\"It will print the updated inventory report\"\"\"\n", + " print(\"Updated Inventory Report:\")\n", + " for item in inventory:\n", + " print(f\"Inventory of {item} : {inventory[item]}\")\n", + " return inventory\n", + "\n", + "print_updated_inventory(inventory)\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +429,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,