diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..01773c39 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,112 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {'t-shirt': 50, 'mug': 40, 'hat': 30, 'book': 20, 'keychain': 10}\n", + "Customer orders: {'mug': 5, 'book': 10, 'hat': 20}\n", + "Order Statistics:\n", + " Total Products Ordered: 35\n", + " Percentage of Products Ordered: 23.33%\n" + ] + } + ], + "source": [ + "# My code:\n", + "\n", + "# This code defines a list of products, creates an empty inventory dictionary, and prompts the user to input the quantity for each product. \n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "quantity = input(\"Please input the quantity for each product: t-shirt: \")\n", + "inventory[\"t-shirt\"] = int(quantity)\n", + "quantity = input(\"Please input the quantity for each product: mug: \")\n", + "inventory[\"mug\"] = int(quantity)\n", + "quantity = input(\"Please input the quantity for each product: hat: \")\n", + "inventory[\"hat\"] = int(quantity)\n", + "quantity = input(\"Please input the quantity for each product: book: \")\n", + "inventory[\"book\"] = int(quantity)\n", + "quantity = input(\"Please input the quantity for each product: keychain: \")\n", + "inventory[\"keychain\"] = int(quantity)\n", + "print(\"Inventory:\", inventory)\n", + "\n", + "# This code prompts the user to input three product names and their quantities, and stores them in a dictionary called customer_orders. Finally, it prints the customer orders.\n", + "customer_orders = {}\n", + "customer_name1 = input(\"Please enter the first product name: \")\n", + "quantity_prod1 = int(input(\"Please enter the quantity for the first product: \"))\n", + "customer_orders[customer_name1] = quantity_prod1\n", + "\n", + "customer_name2 = input(\"Please enter the second product name: \")\n", + "quantity_prod2 = int(input(\"Please enter the quantity for the second product: \"))\n", + "customer_orders[customer_name2] = quantity_prod2\n", + "\n", + "customer_name3 = input(\"Please enter the third product name: \")\n", + "quantity_prod3 = int(input(\"Please enter the quantity for the third product: \"))\n", + "customer_orders[customer_name3] = quantity_prod3\n", + "print(\"Customer orders:\", customer_orders)\n", + "\n", + "\n", + "# This code calculates the total of the orders ordered by the customer and the percentage of the total inventory that has been ordered. \n", + "total_order = int(quantity_prod1) + int(quantity_prod2) + int(quantity_prod3)\n", + "\n", + "total_inventory = sum(inventory.values())\n", + "\n", + "fill_rate = total_order / total_inventory\n", + "\n", + "order_status = (total_order, fill_rate)\n", + "\n", + "print(f\"\"\"Order Statistics:\n", + " Total Products Ordered: {total_order}\n", + " Percentage of Products Ordered: {fill_rate:.2%}\"\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory:\n", + "t-shirt: 49\n", + "mug: 39\n", + "hat: 29\n", + "book: 19\n", + "keychain: 9\n" + ] + } + ], + "source": [ + "# Modifying the inventory by subtracting 1 from each product quantity.\n", + "\n", + "updated_inventory = inventory.copy()\n", + "for product in inventory:\n", + " updated_inventory[product] = updated_inventory[product] - 1\n", + "print(\"Updated Inventory:\")\n", + "for product, quantity in updated_inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +169,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.5" } }, "nbformat": 4,