diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..f343fd3 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,268 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "96c6c262", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "013581f7", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " inventory[product] = int(input(\"Enter the quantity of the product: \"))\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "db16832e", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = initialize_inventory(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "3094bb29", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 15, 'hat': 12, 'book': 1, 'keychain': 3}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "b83ba19f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thank you for your order!\n" + ] + } + ], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n", + " while True:\n", + " customer_order = input(\"Which product would you like to order? \")\n", + " customer_orders.add(customer_order)\n", + "\n", + " extra_order = input(\"Would you like to order another product? (yes/no) \").lower()\n", + " if extra_order != 'yes':\n", + " print(\"Thank you for your order!\")\n", + " break\n", + "\n", + " \n", + " return customer_orders\n", + "\n", + "customer_orders = get_customer_orders()" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "id": "5f8348b7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "id": "38b16cb5", + "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", + " return inventory\n", + "\n", + "inventory = update_inventory(customer_orders, inventory)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "7fe63fd8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 2, 'mug': 1, 'hat': -1, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "4249c6d8", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " total_orders = len(customer_orders)\n", + " total_percentage = (total_orders / len(products)) * 100\n", + " \n", + " return total_orders, total_percentage\n", + "\n", + "total_orders, total_percentage = calculate_order_statistics(customer_orders, products)" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "593d258b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 20.0)\n" + ] + } + ], + "source": [ + "print(calculate_order_statistics(customer_orders, products))" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "id": "9cfd8934", + "metadata": {}, + "outputs": [], + "source": [ + "order_statistics = calculate_order_statistics(customer_orders, products)" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "id": "17ac8752", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " total_orders, total_percentage = order_statistics\n", + " print(\"Total orders: \", total_orders)\n", + " print(\"Total percentage of products ordered: \", total_percentage)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "id": "61670600", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total orders: 1\n", + "Total percentage of products ordered: 20.0\n", + "None\n" + ] + } + ], + "source": [ + "print(print_order_statistics(order_statistics))" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "7d94e55a", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " for product, quantity in inventory.items():\n", + " print(\"Inventory: \", product, \": \", quantity)" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "id": "2ecf04ec", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: t-shirt : 2\n", + "Inventory: mug : 1\n", + "Inventory: hat : 0\n", + "Inventory: book : 4\n", + "Inventory: keychain : 5\n", + "None\n" + ] + } + ], + "source": [ + "print(print_updated_inventory(inventory))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "46cc2890", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +318,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,