diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..54432c7 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,6 +43,156 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "200defb6-e54d-4685-b2b9-069f193b637c", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory (list_products):\n", + " for product in list_products :\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "f47515b1-dcf4-4f65-8d7d-953c31c0d80c", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " customer_status = True\n", + " while customer_status == True:\n", + " customer_orders.add(input(f\"Enter the name of a product that the customer wants : {list_products}\"))\n", + " customer_answer = (input(f\" Want to do another purchase, answser : yes or no\"))\n", + " if customer_answer == \"yes\" :\n", + " customer_status = True\n", + " else :\n", + " customer_status = False\n", + " break\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "71eaf890-b49f-468f-872a-0db03fdddb5f", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "28d6cde5-cc58-4f28-8e51-194f33dd7e71", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics (customer_orders,list_products,inventory) :\n", + " order_statistics = {}\n", + " total_prod_ordered = len(customer_orders)\n", + " order_statistics[\"total_prod_ordered\"] = total_prod_ordered\n", + " \n", + " total_inventory = sum(inventory.values())\n", + " percentage_products_ordered = (total_prod_ordered / total_inventory)*100\n", + " order_statistics [\"percentage_products_ordered\"] = percentage_products_ordered\n", + " return order_statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "0b27bd5d-1d7d-46af-9326-0c5d4b486947", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics (order_statistics):\n", + " print(f\"Total Products Ordered: {order_statistics[\"total_prod_ordered\"]}.\")\n", + " print(f\"Percentage of Products Ordered: {order_statistics[\"percentage_products_ordered\"]:.2f}%. \")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "1aad97d7-d883-41ad-b3c2-d58116c87d81", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory (inventory) :\n", + " print(f\"This is the inventory after customer order :\")\n", + " for product, quantity in inventory.items():\n", + " print (f\"{product} : {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "08c098ac-4209-4627-8125-0e90b4aa140d", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity of t-shirt: 1\n", + "Enter the quantity of mug: 2\n", + "Enter the quantity of hat: 3\n", + "Enter the quantity of book: 4\n", + "Enter the quantity of keychain: 5\n", + "Enter the name of a product that the customer wants : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n", + " Want to do another purchase, answser : yes or no yes\n", + "Enter the name of a product that the customer wants : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] hat\n", + " Want to do another purchase, answser : yes or no yes\n", + "Enter the name of a product that the customer wants : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n", + " Want to do another purchase, answser : yes or no no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 3.\n", + "Percentage of Products Ordered: 25.00%. \n", + "This is the inventory after customer order :\n", + "t-shirt : 1\n", + "mug : 1\n", + "hat : 2\n", + "book : 3\n", + "keychain : 5\n" + ] + } + ], + "source": [ + "list_products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "initialize_inventory(list_products)\n", + "customer_orders = get_customer_orders()\n", + "update_inventory(customer_orders, inventory)\n", + "order_statistics = calculate_order_statistics (customer_orders,list_products,inventory)\n", + "print_order_statistics (order_statistics)\n", + "print_updated_inventory (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ccf9fb62-6df1-49c0-ae16-6a6f09c6a72e", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -61,7 +211,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,