diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..27429ec 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,13 +43,96 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "63afd520-7b15-4433-88c8-248f4bdd43f6", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the number of your book: 2\n", + "Enter the number of your pen: 3\n", + "Enter the number of your notebook: 2\n", + "Enter the number of your hat: 3\n", + "Enter the number of your mug: 54\n", + "Products ordered: book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total of products ordered are 1 and the percentage of products ordered are 20.00%\n", + "book: 1\n", + "pen: 3\n", + "notebook: 2\n", + "hat: 3\n", + "mug: 54\n" + ] + } + ], + "source": [ + "products = ['book', 'pen', 'notebook', 'hat', 'mug']\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " number = int(input(f\"Enter the number of your {product}: \"))\n", + " inventory[product] = number\n", + " return inventory\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "def get_customer_orders():\n", + " add_order = input(\"Products ordered: \")\n", + " customers_orders = {item.strip() for item in add_order.split(',') if item.strip()}\n", + " return customers_orders\n", + "\n", + "customer_orders = get_customer_orders() \n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " return inventory\n", + "inventory = update_inventory(customer_orders, inventory)\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_ordered = len(customer_orders)\n", + " percentage = (total_ordered / len(products)) * 100\n", + " return total_ordered, percentage\n", + "order_stats = calculate_order_statistics(customer_orders, products)\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " total_ordered, percentage = order_statistics\n", + " print(f\"Total of products ordered are {total_ordered} and the percentage of products ordered are {percentage:.2f}%\")\n", + "print_order_statistics(order_stats)\n", + "\n", + "def print_updated_inventory(inventory):\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n", + "\n", + "print_updated_inventory(inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fe57a5fc-d187-496e-bcf4-d4e9a3146a7f", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -61,7 +144,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,