diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..c4cef2de 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -36,13 +36,12 @@ " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", " \n", " Store these statistics in a tuple called `order_status`.\n", + "inventory = {\n", + " \"apple\": 10,\n", + " \"banana\": 20,\n", + " \"orange\": 15\n", + " \n", "\n", - "8. Print the order statistics using the following format:\n", - " ```\n", - " Order Statistics:\n", - " Total Products Ordered: \n", - " Percentage of Products Ordered: % \n", - " ```\n", "\n", "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", "\n", @@ -50,11 +49,196 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Excercise #1" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "products = ['t-shirt','mug', 'hat','book','keychain']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Exercise #2" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = { }" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for product in products:\n", + " quantity = int(input(f'Enter quantity of {product} available in the inventory: '))\n", + " inventory[product] = quantity\n", + " print(\"updated inventory:\", inventory)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Excercise #4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "customer_order = {}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'product' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(product)\n", + "\u001b[0;31mNameError\u001b[0m: name 'product' is not defined" + ] + } + ], + "source": [ + "for products in products:\n", + " name_of_products = input(f'Enter three names of products that costumer wants to order:')\n", + " customer_order.append(name_of_products)\n", + " print (\"customer order:\", Customer_order)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Excercise #7" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = { \"apple\": 10, \"banana\": 20, \"orange\": 15}\n", + "\n", + "customer_orders = {\"apple\", \"banana\", \"apple\"}\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "\n", + "available_products = sum(inventory.values())\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Excercise #8" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {\n", + " \"apple\": 10,\n", + " \"banana\": 20,\n", + " \"orange\": 15\n", + "}\n", + "\n", + "customer_orders = {\"apple\", \"banana\", \"apple\"}\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "\n", + "available_products = sum(inventory.values())\n", + "\n", + "percentage_ordered = (total_products_ordered / available_products) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "print(\"Order status:\", order_status)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Excercise #9" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated inventory: {'apple': 9, 'banana': 19, 'orange': 14}\n" + ] + } + ], + "source": [ + "inventory = {\n", + " \"apple\": 10,\n", + " \"banana\": 20,\n", + " \"orange\": 15\n", + "}\n", + "\n", + "for product in inventory:\n", + " inventory[product] -= 1\n", + "\n", + "print(\"Updated inventory:\", inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +252,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,