From 956741fa12f7424c32a5734bd89d83413c075af1 Mon Sep 17 00:00:00 2001 From: VeliaAlam Date: Mon, 28 Jul 2025 11:51:26 +0200 Subject: [PATCH] Done --- .DS_Store | Bin 0 -> 6148 bytes lab-python-functions.ipynb | 262 ++++++++++++++++++++++++++++++++++++- 2 files changed, 259 insertions(+), 3 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 0:\n", + " inventory[order] -= 1\n", + " print(f\"Order for {order} processed. Remaining quantity: {inventory[order]}\")\n", + " else:\n", + " print(f\"Sorry, {order} is out of stock.\")\n", + " else:\n", + " print(f\"{order} is not available in the inventory.\")\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "id": "2e54e87a", + "metadata": {}, + "outputs": [], + "source": [ + "#4. Define a function named calculate_order_statistics that takes customer_orders and products as parameters\n", + "def calculate_order_statistics(customer_orders, products):\n", + " #Implement the code for calculating the order statistics (total products ordered, and percentage of unique products ordered)\n", + " total_orders = len(customer_orders)\n", + " unique_products = set(customer_orders)\n", + " total_products = len(products)\n", + " percentage_unique = (len(unique_products) / total_products) * 100 if total_products > 0 else 0\n", + " return total_orders, percentage_unique" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "id": "8cd98b3a", + "metadata": {}, + "outputs": [], + "source": [ + "#5. Define a function named print_order_statistics that takes customer_orders and products as parameters\n", + "def print_order_statistics(customer_orders, products):\n", + " #Implement the code for printing the order statistics\n", + " total_orders, percentage_unique = calculate_order_statistics(customer_orders, products)\n", + " print(f\"Total products ordered: {total_orders}\")\n", + " print(f\"Percentage of unique products ordered: {percentage_unique:.2f}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "1754c830", + "metadata": {}, + "outputs": [], + "source": [ + "#6. Define a function named print_updated_inventory that takes inventory as a parameter\n", + "def print_updated_inventory(inventory):\n", + " #Implement the code for printing the updated inventory\n", + " print(\"Updated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity} units\")" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "e2ed4623", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Welcome to the inventory management system!\n", + "\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity for t-shirt: 3\n", + "Enter the quantity for mug: 4\n", + "Enter the quantity for hat: 5\n", + "Enter the quantity for book: 6\n", + "Enter the quantity for keychain: 7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Inventory initialized.\n", + "\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a product name (or 'done' to finish): mug\n", + "Enter a product name (or 'done' to finish): jeans\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid product. Please choose from: t-shirt, mug, hat, book, keychain\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a product name (or 'done' to finish): booik\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid product. Please choose from: t-shirt, mug, hat, book, keychain\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a product name (or 'done' to finish): book\n", + "Enter a product name (or 'done' to finish): Book\n", + "Enter a product name (or 'done' to finish): BOOK\n", + "Enter a product name (or 'done' to finish): 345\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid product. Please choose from: t-shirt, mug, hat, book, keychain\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a product name (or 'done' to finish): MUG\n", + "Enter a product name (or 'done' to finish): DONE\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order for book processed. Remaining quantity: 5\n", + "Order for mug processed. Remaining quantity: 3\n", + "Total products ordered: 2\n", + "Percentage of unique products ordered: 40.00%\n", + "Updated Inventory:\n", + "t-shirt: 3 units\n", + "mug: 3 units\n", + "hat: 5 units\n", + "book: 5 units\n", + "keychain: 7 units\n", + "\n", + "Thank you for using the inventory management system!\n" + ] + } + ], + "source": [ + "#7.Call the functions in the appropriate sequence to execute the program and manage customer orders\n", + "def main():\n", + " print(\"\\nWelcome to the inventory management system!\\n\")\n", + " inventory = initialize_inventory(products)\n", + " print(\"\\nInventory initialized.\\n\")\n", + "\n", + " customer_orders = get_customer_orders()\n", + " updated_inventory = update_inventory(customer_orders, inventory)\n", + " \n", + " print_order_statistics(customer_orders, products)\n", + " print_updated_inventory(updated_inventory)\n", + " \n", + " print(\"\\nThank you for using the inventory management system!\")\n", + "\n", + "if __name__ == \"__main__\":\n", + " main()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "14deb3c7-18a7-4821-a374-4c04156b977a", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -61,7 +317,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,