diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..d16ff44 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,270 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "9dbad25b", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " quantity = int(input(f\"How many {product}s are available? \"))\n", + " inventory[product] = quantity\n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "bbe0626d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "13ae2d07", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + " product = input(\"Enter a product to order: \")\n", + " customer_orders.add(product)\n", + "\n", + " answer = input(\"Do you want to add another product? (yes/no): \")\n", + "\n", + " if answer.lower() == \"no\":\n", + " break\n", + "\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "9db54c88", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book', 'table', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "customer_orders = get_customer_orders()\n", + "\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "85d9ab7f", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "0bbb48dd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 9, 'hat': 9, 'book': 9, 'keychain': 10}\n" + ] + } + ], + "source": [ + "updated_inventory = update_inventory(customer_orders, inventory)\n", + "\n", + "print(updated_inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "db337d78", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + "\n", + " percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + " return total_products_ordered, percentage_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "1cbb33ec", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(4, 80.0)\n" + ] + } + ], + "source": [ + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print(order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "171db87c", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " print(\"Order Statistics:\")\n", + " print(f\"Total Products Ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage of Products Ordered: {order_statistics[1]:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "e531d0f2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 4\n", + "Percentage of Products Ordered: 80.00%\n" + ] + } + ], + "source": [ + "print_order_statistics(order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "5c4b9159", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory:\")\n", + "\n", + " for product in inventory:\n", + " print(f\"{product}: {inventory[product]}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "fe9e8a63", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory:\n", + "t-shirt: 10\n", + "mug: 9\n", + "hat: 9\n", + "book: 9\n", + "keychain: 10\n" + ] + } + ], + "source": [ + "print_updated_inventory(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "09d1a9f4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 4\n", + "Percentage of Products Ordered: 80.00%\n", + "Updated Inventory:\n", + "t-shirt: 10\n", + "mug: 9\n", + "hat: 9\n", + "book: 9\n", + "keychain: 10\n" + ] + } + ], + "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", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print_order_statistics(order_statistics)\n", + "\n", + "print_updated_inventory(inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +320,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,