diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..bfea9b20 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,160 @@ "\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": 15, + "metadata": {}, + "outputs": [], + "source": [ + "#1.Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "\n", + "#2. Create an empty dictionary called `inventory`.\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "# 3.Ask the user quantity\n", + "inventory['t-shirt'] = int(input(\"Enter quantity t-shirt: \"))\n", + "inventory['mug'] = int(input(\"Enter quantity mug: \"))\n", + "inventory['hat'] = int(input(\"Enter quantity hat: \"))\n", + "inventory['book'] = int(input(\"Enter quantity book: \"))\n", + "inventory['keychain'] = int(input(\"Enter quantity keychain: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "# 4.Create an empty set called `customer_orders`.\n", + "customer_orders = set()\n", + "\n", + "# 5.5. Ask the user to input the name of three products that a customer wants to order \n", + "# \\(from those in the products list,\n", + "# \\ meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". \\\n", + "# Add each product name to the `customer_orders` set.\n", + "customer_orders.add(input(\"Enter first product name: \"))\n", + "customer_orders.add(input(\"Enter second product name: \"))\n", + "customer_orders.add(input(\"Enter third product name: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer orders: {'t-shirt', 'book', 'mug'}\n" + ] + } + ], + "source": [ + "# 6. Print the products in the `customer_orders` set.\n", + "print(f\"Customer orders: {customer_orders}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "#7 Calculate the following order statistics:/\n", + "# - Total Products Ordered: The total number of products in the `customer_orders` set. / \n", + "# - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", + "# /Store these statistics in a tuple called `order_status`.\n", + "total_product = len(customer_orders)\n", + "percentage_products_ordered = (total_product / len(products)) * 100\n", + "order_status = (total_product, percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n" + ] + } + ], + "source": [ + "# 8. Order Statistics: \\\n", + "# Total Products Ordered: \\\n", + "# Percentage of Products Ordered: % \n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "# 9. Update the inventory by subtracting 1 from the quantity of each product. /\n", + "# Modify the `inventory` dictionary accordingly.\n", + "for product in customer_orders:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Update Inventory:\n", + "t-shirt: 4\n", + "mug: 4\n", + "hat: 5\n", + "book: 4\n", + "keychain: 5\n" + ] + } + ], + "source": [ + "#10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "print(\"Update Inventory:\")\n", + "print(\"t-shirt: \", inventory['t-shirt'])\n", + "print(\"mug: \", inventory['mug'])\n", + "print(\"hat: \", inventory['hat'])\n", + "print('book: ', inventory['book'])\n", + "print('keychain: ', inventory['keychain'])" + ] + }, + { + "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 +217,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.10.2" } }, "nbformat": 4,