diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..07b6a4ae 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,212 @@ "\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": [ + { + "data": { + "text/plain": [ + "['t-shirts', 'mug', 'hat', 'book', 'keychain']" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "products=[\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]\n", + "products" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "inventory={}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "inventory[\"t-shirt\"]=int(input(\"enter the quantity of t-shirt\"))\n", + "inventory[\"mug\"]=int(input(\"enter the quantity of mug\"))\n", + "inventory[\"hat\"]=int(input(\"enter the quantity of hat\"))\n", + "inventory[\"book\"]=int(input(\"enter the quantity of book\"))\n", + "inventory[\"keychain\"]=int(input(\"enter the quantity of keychain\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders=set()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "order1=input(\"enter your order\")\n", + "order2=input(\"enter your order\")\n", + "order3=input(\"enter your order\")\n", + "if order1 in products:\n", + " customer_orders.add(order1)\n", + "else:\n", + " print(\"order1 not found\")\n", + "if order2 in products:\n", + " customer_orders.add(order2)\n", + "else:\n", + " print(\"order2 not found\")\n", + "if order3 in products:\n", + " customer_orders.add(order3)\n", + "else:\n", + " print(\"order3 not found\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "60.0\n", + "(3, 60.0)\n" + ] + } + ], + "source": [ + "total_products_order=len(customer_orders)\n", + "print(total_products_order)\n", + "percentage_ordered=(total_products_order / len(products)) * 100\n", + "print(percentage_ordered)\n", + "order_status=(total_products_order,percentage_ordered)\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0\n" + ] + } + ], + "source": [ + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirts': 9, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 49}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory[\"t-shirt\"] -=1\n", + "inventory[\"mug\"] -=1\n", + "inventory[\"hat\"] -=1\n", + "inventory[\"book\"] -=1\n", + "inventory[\"keychain\"] -=1\n", + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirts: 9\n", + "mug: 19\n", + "hat: 29\n", + "book: 39\n", + "keychain: 49\n" + ] + } + ], + "source": [ + "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": [] + }, + { + "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 +269,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.9" } }, "nbformat": 4,