diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..2da8eb6 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,221 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "9525f028", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "2a41c21d", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "7c98f4f8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8}\n" + ] + } + ], + "source": [ + "inventory = initialize_inventory(products)\n", + "print(\"Inventory:\", inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "af331c34", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer Orders: {'book', 'hat', 'mug'}\n" + ] + } + ], + "source": [ + "def get_customer_orders(): \n", + " customer_orders = set()\n", + " while True:\n", + " product_name = input(\"Enter product name: \")\n", + " customer_orders.add(product_name)\n", + " continue_entering = input(\"Do you want to enter another product? (yes/no): \").lower()\n", + " if continue_entering != \"yes\":\n", + " break\n", + " return customer_orders\n", + "\n", + "customer_orders = get_customer_orders()\n", + "print(\"Customer Orders:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "2c5df9de", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory: {'t-shirt': 4, 'mug': 4, 'hat': 5, 'book': 6, 'keychain': 8}\n" + ] + } + ], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " product = product.strip()\n", + " inventory[product] = inventory[product] - 1\n", + "\n", + " return inventory\n", + "updated_inventory = update_inventory(customer_orders, inventory)\n", + "print(\"Updated Inventory:\", updated_inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "2e0d1db4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order statistics: (3, 60.0)\n" + ] + } + ], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_ordered = (len(customer_orders) / len(products)) * 100\n", + "\n", + " return (total_products_ordered, percentage_ordered)\n", + "\n", + "\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print(\"Order statistics:\", order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "5a1b4e4b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0\n" + ] + } + ], + "source": [ + "def print_order_statistics(order_statistics):\n", + " print(\"Total Products Ordered:\", order_statistics[0])\n", + " print(\"Percentage of Products Ordered:\", order_statistics[1])\n", + "\n", + "\n", + "print_order_statistics(order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "6e9e377d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 4\n", + "mug: 4\n", + "hat: 5\n", + "book: 6\n", + "keychain: 8\n" + ] + } + ], + "source": [ + "def print_updated_inventory(inventory):\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n", + "\n", + "\n", + "print_updated_inventory(updated_inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "6ed63107", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 40.0\n", + "t-shirt: 10\n", + "mug: 19\n", + "hat: 30\n", + "book: 39\n", + "keychain: 50\n" + ] + } + ], + "source": [ + "inventory = initialize_inventory(products)\n", + "\n", + "customer_orders = get_customer_orders()\n", + "\n", + "updated_inventory = update_inventory(customer_orders, inventory)\n", + "\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print_order_statistics(order_statistics)\n", + "\n", + "print_updated_inventory(updated_inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +271,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,