diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..47d64a2 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,6 +43,159 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "10c44d8c-7291-4705-a000-66f544b0efb3", + "metadata": {}, + "outputs": [], + "source": [ + "#1. initialize_inventory\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + "\n", + " for item in products:\n", + " quantity = int(input(f\"Enter {item} quantity: \"))\n", + " inventory[item] = quantity\n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "620b51d6-2737-494b-ba9c-931bc1764c69", + "metadata": {}, + "outputs": [], + "source": [ + "#2. get_customer_orders\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " add_product = \"yes\"\n", + "\n", + " while add_product == \"yes\":\n", + " item = input(\"What would you like to order: t-shirt, mug, hat, book or keychain? \").lower()\n", + "\n", + " if item in products:\n", + " customer_orders.add(item)\n", + " else:\n", + " print(\"Invalid product or wrongly written. Please choose one from the list.\")\n", + "\n", + " add_product = input(\"Do you want to add another product? (yes/no) \").lower()\n", + "\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "9a905fe9-167d-4ba4-98c2-b69d31708749", + "metadata": {}, + "outputs": [], + "source": [ + "#3. update_inventory\n", + "def update_inventory(customer_orders, inventory):\n", + " for item in customer_orders:\n", + " inventory[item] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "659838c5-89a5-40f9-8960-e690013459a0", + "metadata": {}, + "outputs": [], + "source": [ + "#4. calculate_order_statistics\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_products_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + " return total_products_ordered, percentage_products_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "c8c3cb91-f714-42c5-b12d-5cc4afe4fedf", + "metadata": {}, + "outputs": [], + "source": [ + "#5. print_order_statistics\n", + "def print_order_statistics(order_statistics):\n", + " total_products_ordered, percentage_products_ordered = order_statistics\n", + "\n", + " labels = [\"Total Products Ordered:\", \"Percentage of Products Ordered:\"]\n", + "\n", + " for label, value in zip(labels, order_statistics):\n", + " print(label, value)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "a011121b-67e1-43bf-b50f-f702b738802c", + "metadata": {}, + "outputs": [], + "source": [ + "#6. print_updated_inventory\n", + "def print_updated_inventory(inventory):\n", + " for item, quantity in inventory.items():\n", + " print(item.title() + \":\", quantity)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "03cda061-2ceb-44b6-b951-2d43a51e819d", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter t-shirt quantity: 1\n", + "Enter mug quantity: 1\n", + "Enter hat quantity: 1\n", + "Enter book quantity: 1\n", + "Enter keychain quantity: 1\n", + "What would you like to order: t-shirt, mug, hat, book or keychain? mug\n", + "Do you want to add another product? (yes/no) yes\n", + "What would you like to order: t-shirt, mug, hat, book or keychain? hat\n", + "Do you want to add another product? (yes/no) no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 40.0\n", + "T-Shirt: 1\n", + "Mug: 0\n", + "Hat: 0\n", + "Book: 1\n", + "Keychain: 1\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "customer_orders = get_customer_orders()\n", + "\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print_order_statistics(order_statistics)\n", + "\n", + "update_inventory(customer_orders, inventory)\n", + "\n", + "print_updated_inventory(inventory)" + ] } ], "metadata": { @@ -61,7 +214,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,