diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..b493862 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,90 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "983e99d7", + "metadata": {}, + "outputs": [], + "source": [ + "# Define a function named `initialize_inventory` that takes `products` as a parameter.\n", + "# Initializes the inventory dictionary using a loop and user input.\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " value = int(input(f'How many {product}s are in the inventory? '))\n", + " inventory[product] = value\n", + " return inventory\n", + "# Define a function named `get_customer_orders` that takes no parameters. Inside the function, implement \n", + "# the code for prompting the user to enter the product names using a loop. The function should return the\n", + "# `customer_orders` set.\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " answer = 'yes'\n", + " while answer == 'yes':\n", + " customer_orders.add(input('Please type a product you would like to purchase'))\n", + " answer = input('Would you like to add another product to your order? (yes/no)')\n", + " while answer != 'yes' and answer!= 'no':\n", + " print('That is an invalid input, please answer yes or no')\n", + " answer = input('Would you like to add another product to your order? (yes/no)')\n", + " return customer_orders\n", + "# Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters\n", + "# Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", + "def update_inventory(customer_orders, inventory):\n", + " for item in customer_orders:\n", + " inventory[item] -= 1\n", + " return inventory\n", + "# Define a function named `calculate_order_statistics` that takes `customer_orders` and `products` \n", + "# as parameters. Inside the function, implement the code for calculating the order statistics\n", + "# (total products ordered, and percentage of unique products ordered). The function should return these values.\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percent_unique = total_products_ordered/len(products)*100\n", + " order_statistics = [total_products_ordered, percent_unique]\n", + " return order_statistics\n", + "# Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. Inside the \n", + "# function, implement the code for printing the order statistics.\n", + "def print_order_statistics(order_statistics):\n", + " print(f'The customer ordered {order_statistics[0]} products')\n", + " print(f'This represents the {order_statistics[1]}% of products in the inventory')\n", + "# Define a function named `print_updated_inventory` that takes `inventory` as a parameter. Inside the function, \n", + "# implement the code for printing the updated inventory.\n", + "def print_updated_inventory(inventory):\n", + " print(f'The updated inventory after customer order is {inventory}')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "0231d252", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The customer ordered 1 products\n", + "This represents the 33.33333333333333% of products in the inventory\n", + "The updated inventory after customer order is {'shirt': 5, 'book': 4, 'bottle': 5}\n" + ] + } + ], + "source": [ + "products = ['shirt', 'book', 'bottle']\n", + "inventory = initialize_inventory(products)\n", + "customer_orders = get_customer_orders()\n", + "inventory = update_inventory(customer_orders, inventory)\n", + "order_statistics = calculate_order_statistics(customer_orders,products)\n", + "print_order_statistics(order_statistics)\n", + "print_updated_inventory(inventory)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +140,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,