diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..742aead0 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,218 @@ "\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": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "#1 \n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print (products)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{}\n" + ] + } + ], + "source": [ + "#2 \n", + "inventory ={}\n", + "print (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 500, 'mug': 400, 'hat': 300, 'book': 40, 'keychain': 50}\n" + ] + } + ], + "source": [ + "#3\n", + "for item in products: \n", + " value = int(input(f\"Enter the quantity for {item}: \"))\n", + " inventory[item] = value\n", + "print (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n" + ] + } + ], + "source": [ + "#4\n", + "customer_orders = set()\n", + "print (customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 't-shirt', 'book'}\n" + ] + } + ], + "source": [ + "#5\n", + "product_1 = input(\"Enter a product name:\")\n", + "product_2 = input(\"Enter a product name:\")\n", + "product_3 = input(\"Enter a product name:\")\n", + "customer_orders.add(product_1)\n", + "customer_orders.add(product_2)\n", + "customer_orders.add(product_3)\n", + "print (customer_orders)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 't-shirt', 'book'}\n" + ] + } + ], + "source": [ + "#6\n", + "print (customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1290, 0.23255813953488372)\n" + ] + } + ], + "source": [ + "#7\n", + "total_numbers_orders = len(customer_orders)\n", + "total_inventory_values = sum(inventory.values())\n", + "percentage_of_products_ordered = (total_numbers_orders/total_inventory_values)*100\n", + "order_status= (total_inventory_values , percentage_of_products_ordered)\n", + "print (order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 0.23255813953488372 %\n" + ] + } + ], + "source": [ + "#8 Order statistics\n", + "print (\"Total Products Ordered:\",total_numbers_orders)\n", + "print (\"Percentage of Products Ordered:\",percentage_of_products_ordered,\"%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 499, 'mug': 399, 'hat': 299, 'book': 39, 'keychain': 49}\n" + ] + } + ], + "source": [ + "#9\n", + "for product in inventory: \n", + " inventory[product] = inventory[product] -1\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory Status:\n", + "t-shirt: 499\n", + "mug: 399\n", + "hat: 299\n", + "book: 39\n", + "keychain: 49\n" + ] + } + ], + "source": [ + "#10\n", + "print (\"Updated Inventory Status:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +275,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,