diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..f9f7bea 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,6 +43,139 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df56862e-4a7d-430f-9fd3-ee9b56c9e7e7", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9096f556-89ea-4654-a93f-cc192fb0f1ef", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + " \n", + " for product in products:\n", + " quantity = int(input(f\"How many {product} are in stock? \"))\n", + " inventory[product] = quantity\n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e6af1698-515b-45f7-a2a5-a95eb50a54e9", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " \n", + " customer_orders = set()\n", + "\n", + " product = input(\"Enter a product you want to order: \")\n", + " customer_orders.add(product)\n", + "\n", + " add_another_product = input(\"Do you want to add another product? (yes/no): \")\n", + "\n", + " while add_another_product == \"yes\":\n", + " product = input(\"Enter a product you want to order: \")\n", + " customer_orders.add(product) \n", + " \n", + " add_another_product = input(\"Do you want to add another product? (yes/no): \") \n", + "\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ad1c3d68-9fe2-453f-8069-dacbb50eb788", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " inventory[product] = inventory[product] - 1\n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "abd6f136-3068-4ba2-a547-2480daad3641", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " \n", + " total_products_ordered = len(customer_orders)\n", + " percentage_ordered = (len (customer_orders) / len(products) * 100)\n", + " order_statistics = (total_products_ordered, percentage_ordered)\n", + "\n", + " return order_statistics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6784e50-1db8-46da-8ba1-24866f3cec0b", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " total_products_ordered, percentage_ordered = order_statistics\n", + " \n", + " print(\"Order Statistics:\")\n", + " print(\"Total Products Ordered:\", total_products_ordered)\n", + " print(f\"Percentage of Products Ordered: {percentage_ordered}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "998de9a0-bb32-4f25-80e2-aebbfc7f3b6e", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory:\")\n", + " \n", + " for product, quantity in inventory.items(): \n", + " print(product, \":\", quantity) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6885596-cf0f-4c9e-be97-87e5b51bba28", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "customer_orders = get_customer_orders()\n", + "\n", + "inventory = update_inventory(customer_orders, inventory)\n", + "\n", + "statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print_order_statistics(statistics) \n", + "\n", + "print_updated_inventory(inventory)" + ] } ], "metadata": { @@ -61,7 +194,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,