diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..205e123 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,13 +43,214 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "c5be3342-a087-4059-9a43-6d4690a4938d", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the qty of ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 5\n", + "Enter the qty of ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 4\n", + "Enter the qty of ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 2\n", + "Enter the qty of ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 1\n", + "Enter the qty of ['t-shirt', 'mug', 'hat', 'book', 'keychain'] 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Initialized Inventory: {'t-shirt': 5, 'mug': 4, 'hat': 2, 'book': 1, 'keychain': 4}\n" + ] + } + ], + "source": [ + "#1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " qty = int(input(f\"Enter the qty of {products}\"))\n", + " inventory [product] = qty\n", + " return inventory \n", + "inventory = initialize_inventory(products)\n", + "print (\"Initialized Inventory:\", inventory)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "3c80f155-9808-48f1-ae6b-5bb6cbf45c2c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the customer orders are : {'mug', 'hat', 'book'}\n" + ] + } + ], + "source": [ + "#2\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True: # Loop continues until break\n", + " product_name = input(\"Enter a product name you would like to order or type 'stop' to finish: \")\n", + " \n", + " # Check if the user entered 'stop', with lowercasing and stripping for safety\n", + " if product_name == \"stop\":\n", + " break # Exit the loop\n", + "\n", + " customer_orders.add(product_name) # Add the product name to the set\n", + " \n", + " return customer_orders\n", + "print(\"the customer orders are :\",customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "3dd0392f-975c-4a58-9b36-43cf0fbb17e2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Update_inventory is: {'t-shirt': 5, 'mug': 4, 'hat': 2, 'book': 1, 'keychain': 4}\n" + ] + } + ], + "source": [ + "#3\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " print(f\"{product} is in stock.\")\n", + " else:\n", + " print(f\"Product {product} not found in inventory.\")\n", + " return inventory \n", + "print (\" Update_inventory is:\", inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "6d6a1a4d-da20-4d93-8c9d-907d199178f8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the statistics are: 3 60.0\n" + ] + } + ], + "source": [ + "#4 #5\n", + "\n", + "def calculate_order_statistics (customer_orders, inventory):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_of_unique_products_ordered = (total_products_ordered / len(products))*100\n", + "\n", + " return total_products_ordered,percentage_of_unique_products_ordered \n", + "\n", + "customer_orders = {'mug', 'hat', 'book'}\n", + "inventory = {'t-shirt': 5, 'mug': 4, 'hat': 2, 'book': 1, 'keychain': 4}\n", + "\n", + "## Call the function and capture its return values\n", + "total_products_ordered, percentage_of_unique_products_ordered = calculate_order_statistics(customer_orders, inventory) \n", + "\n", + "print(\"the statistics are:\",total_products_ordered, percentage_of_unique_products_ordered)\n", + " \n", + " \n", + " \n", + " \n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "81840795-b741-4f79-a28e-b3b565e809f1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " total products ordered are: 3\n", + "percentage of unique products ordered is: 60.0\n" + ] + } + ], + "source": [ + "#5\n", + "\n", + "def print_order_statistics (order_statistics): # tuple ( total products, % unique value)\n", + " print (order_statistics)\n", + "\n", + "print(f\" total products ordered are: {total_products_ordered}\")\n", + "print(f\"percentage of unique products ordered is: {percentage_of_unique_products_ordered}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "384bbc9e-9114-4114-85b8-48935c072932", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory:\n", + "- t-shirt: 5\n", + "- mug: 4\n", + "- hat: 2\n", + "- book: 1\n", + "- keychain: 4\n" + ] + } + ], + "source": [ + "#6\n", + "\n", + "def print_updated_inventory(inventory):# dictionaty key,Values\n", + " print(\"Updated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"- {product}: {quantity}\")\n", + " \n", + "inventory = {'t-shirt': 5, 'mug': 4, 'hat': 2, 'book': 1, 'keychain': 4} \n", + "print_updated_inventory(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dc01b3c8-eca1-4b97-85b3-c2b851680f68", + "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 +262,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,