diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..14ed002b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,264 @@ "\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": 53, + "metadata": {}, + "outputs": [], + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "inventory={}" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "how many t-shirts ? 5\n", + "how many mugs ? 3\n", + "how many hats ? 12\n", + "how many books ? 23\n", + "how many keychains ? 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 3, 'hat': 12, 'book': 23, 'keychain': 4}\n" + ] + } + ], + "source": [ + "for i in range(len(products)):\n", + " inventory[products[i]]=int(input('how many ' + products[i] + 's?'))\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders=set()" + ] + }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Choose a product from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat'}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Choose a product from ['t-shirt', 'mug', 'book', 'keychain'] mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug'}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Choose a product from ['t-shirt', 'book', 'keychain'] book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "# options=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "# customer_orders=set()\n", + "# for i in range(3):\n", + "# choice= input('Choose a product from ' + str(options))\n", + "# if choice in options:\n", + "# customer_orders.add(choice)\n", + "# options.remove(choice)\n", + "# print(customer_orders)\n", + "# else:\n", + "# choice= input('Choose only a product from the list ' + str(options))\n", + "# customer_orders.append(choice)\n", + "# options.remove(choice)" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Choose a product from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] shoes\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Not a valid item\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Choose a product from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n", + "Choose a product from ['t-shirt', 'mug', 'hat', 'keychain'] hat\n", + "Choose a product from ['t-shirt', 'mug', 'keychain'] mug\n" + ] + } + ], + "source": [ + "options=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "customer_orders=set()\n", + "while len(customer_orders)!=3:\n", + " choice= input('Choose one product from ' + str(options))\n", + " if choice in options:\n", + " customer_orders.add(choice)\n", + " options.remove(choice)\n", + " #print(customer_orders)\n", + " else:\n", + " print('Not a valid item, try again')" + ] + }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [], + "source": [ + "#print('Order Statistics')\n", + "total_number_products=len(customer_orders)\n", + "total=sum(inventory.values())\n", + "#for i in products:\n", + " # total=total+inventory[i]\n", + "percentage_ordered=round(3/total*100,1)\n", + "#print(f\"Total Products Ordered: {total_number_products}\")\n", + "#print(f\"Percentage of Products Ordered: {percentage_ordered}%\" )\n", + "order_status=('Total Products Ordered:',total_number_products,'Percentage of Products Ordered:',percentage_ordered)\n", + "#print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 9.1%\n" + ] + } + ], + "source": [ + "print('Order Statistics')\n", + "#total_number_products=len(customer_orders)\n", + "#total=0\n", + "#for i in products:\n", + "# total=total+inventory[i]\n", + "#percentage_ordered=round(3/total*100,1)\n", + "print(f\"Total Products Ordered: {total_number_products}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_ordered}%\" )\n", + "#order_status=('Total Products Ordered:',total_number_products,'Percentage of Products Ordered:',percentage_ordered)\n", + "#print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [], + "source": [ + "for i in products: #customer_orders:\n", + " if inventory[i]!=0:\n", + " inventory[i]-=1" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are 4 t-shirts\n", + "There are -1 mugs\n", + "There are 8 hats\n", + "There are 19 books\n", + "There are 3 keychains\n" + ] + } + ], + "source": [ + "for key,value in inventory.items():\n", + " print(f\"There are {value} {key}s\")" + ] } ], "metadata": { @@ -68,7 +326,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,