diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..05f945a 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,133 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "3ef0ad65", + "metadata": {}, + "outputs": [], + "source": [ + "# My code here\n", + "# 1.\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " quantity = int(input(f\"How many {product} ?\"))\n", + " inventory[product] = quantity\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "662dd6ae", + "metadata": {}, + "outputs": [], + "source": [ + "# 2.\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " another_order = \"yes\"\n", + "\n", + " while another_order == \"yes\":\n", + " product_name = input(\"Enter a product name: \")\n", + " customer_orders.add(product_name)\n", + " another_order = input(\"Do you want another product? (yes/no): \")\n", + "\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "a6b8d9e4", + "metadata": {}, + "outputs": [], + "source": [ + "# 3.\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "a0a325fb", + "metadata": {}, + "outputs": [], + "source": [ + "# 4.\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders) # Total of customer orders\n", + " percentage = (len(customer_orders) / len(products)) * 100\n", + " return total_products_ordered, percentage" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "4f72136a", + "metadata": {}, + "outputs": [], + "source": [ + "# 5.\n", + "def print_order_statistics(order_statistics):\n", + " print(f\"Total products ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage products ordered: {order_statistics[1]}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "306493f1", + "metadata": {}, + "outputs": [], + "source": [ + "# 6.\n", + "def print_updated_inventory(inventory):\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "b9931681", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total products ordered: 2\n", + "Percentage products ordered: 40.0\n", + "t-shirt: 481\n", + "mug: 43\n", + "hat: 32\n", + "book: 11\n", + "keychain: 3\n" + ] + } + ], + "source": [ + "# 7.\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = initialize_inventory(products)\n", + "customer_orders = get_customer_orders()\n", + "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)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +183,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,