diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..76d7db1 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,317 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "84de27db", + "metadata": {}, + "outputs": [], + "source": [ + "products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "1550e364", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f'Enter the quantity for {product}: '))\n", + " inventory[product] = quantity\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "d6315653", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = initialize_inventory(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "58039c2b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 5, 'mug': 7, 'hat': 2, 'book': 8, 'keychain': 9}" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "4561077c", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "4d374665", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n", + " for i in range(3):\n", + " product = input('Enter a product: ')\n", + " customer_orders.add(product)\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "b77d62b6", + "metadata": {}, + "outputs": [], + "source": [ + "orders = get_customer_orders()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "c1cbdaf5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "orders" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "8ab6880b", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " inventory[product] -= 1\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "c01a0ff2", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = update_inventory(orders, inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "4b5a48a2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 5, 'mug': 6, 'hat': 1, 'book': 7, 'keychain': 9}" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "9a2e853a", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_of_unique_products_ordered = (total_products_ordered / len(products)) * 100\n", + " return total_products_ordered, percentage_of_unique_products_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "11ba4bd0", + "metadata": {}, + "outputs": [], + "source": [ + "order_statistics = calculate_order_statistics(orders, products)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "59fda4ec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 60.0)" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "2c952292", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " total_products_ordered, percentage_of_unique_products_ordered = order_statistics\n", + "\n", + " print('Order Statistics:')\n", + " print('Total Products Ordered:', total_products_ordered)\n", + " print('Percentage of unique products Ordered:', percentage_of_unique_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "04f7388d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of unique products Ordered: 60.0\n" + ] + } + ], + "source": [ + "print_order_statistics(order_statistics)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "47d12f2a", + "metadata": {}, + "outputs": [], + "source": [ + "def print_update_inventory(inventory):\n", + " for product in inventory:\n", + " print(product,\":\", inventory[product])" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "6009b4dc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt : 5\n", + "mug : 6\n", + "hat : 1\n", + "book : 7\n", + "keychain : 9\n" + ] + } + ], + "source": [ + "print_update_inventory(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "8e5d2722", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of unique products Ordered: 60.0\n", + "t-shirt : 5\n", + "mug : 7\n", + "hat : 4\n", + "book : 3\n", + "keychain : 3\n" + ] + } + ], + "source": [ + "products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "orders = get_customer_orders()\n", + "\n", + "inventory = update_inventory(orders, inventory)\n", + "\n", + "order_statistics = calculate_order_statistics(orders, products)\n", + "\n", + "print_order_statistics(order_statistics)\n", + "\n", + "print_update_inventory(inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +367,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4,