diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..a10e1a39 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -9,6 +9,13 @@ "# Lab | Data Structures " ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -50,11 +57,149 @@ "\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": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 64, 'mug': 5, 'hat': 44, 'book': 553, 'keychain': 22}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "inventory[\"t-shirt\"] = int(input(\"Write a quantity of t-shirt\"))\n", + "inventory[\"mug\"] = int(input(\"Write a quantity of mug\"))\n", + "inventory[\"hat\"] = int(input(\"Write a quantity of hat\"))\n", + "inventory[\"book\"] = int(input(\"Write a quantity of book\"))\n", + "inventory[\"keychain\"] = int(input(\"Write a quantity of keychain\"))\n", + "print(inventory)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'book', 'mug'}\n" + ] + } + ], + "source": [ + "costumer_orders = set()\n", + "costumer_orders.add(input(\"Write a product to order\"))\n", + "costumer_orders.add(input(\"Write a product to order\"))\n", + "costumer_orders.add(input(\"Write a product to order\"))\n", + "print(costumer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(costumer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = total_products_ordered / len(products) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 5\n", + "Percentage of Products Ordered: 0.6%\n" + ] + } + ], + "source": [ + "order_status = (total_inventory, percentage_ordered)\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "inventory[\"t-shirt\"] = inventory[\"t-shirt\"] - 1\n", + "inventory[\"mug\"] = inventory[\"mug\"] - 1\n", + "inventory[\"hat\"] = inventory[\"hat\"] - 1\n", + "inventory[\"book\"] = inventory[\"book\"] - 1\n", + "inventory[\"keychain\"] = inventory[\"keychain\"] - 1\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirts: 42\n", + "mugs: 0\n", + "hats: -1\n", + "books: 41\n", + "keychains: 0\n" + ] + } + ], + "source": [ + "print(\"t-shirts:\", inventory[\"t-shirts\"])\n", + "print(\"mugs:\", inventory[\"mugs\"])\n", + "print(\"hats:\", inventory[\"hats\"])\n", + "print(\"books:\", inventory[\"books\"])\n", + "print(\"keychains:\", inventory[\"keychains\"])" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "ds", "language": "python", "name": "python3" }, @@ -68,7 +213,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.12" } }, "nbformat": 4,