diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..b8c0bbc8 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -9,6 +9,165 @@ "# Lab | Data Structures " ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "quantity available of each product:\n" + ] + } + ], + "source": [ + "print(\"quantity available of each product:\")\n", + "for item in products:\n", + " while True:\n", + " try:\n", + " quantity = int(input(f\"Enter quantity for {item}: \"))\n", + " if quantity < 0:\n", + " print(\"Please enter a non-negative integer.\")\n", + " continue\n", + " inventory[item] = quantity\n", + " break\n", + " except ValueError:\n", + " print(\"Invalid input. Please enter an integer.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "customer_order = set()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "three products I want to order: t-shirt, mug, hat, book, keychain\n" + ] + } + ], + "source": [ + "print(\"three products I want to order: t-shirt, mug, hat, book, keychain\")\n", + "for _ in range(3):\n", + " while True:\n", + " product = input(\"t-shirt, mug, hat, book, keychain: \")\n", + " if product in products:\n", + " customer_order.add(product)\n", + " break\n", + " else:\n", + " print(\"Product not available. Please choose from the available products.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "customer's order summary:\n" + ] + } + ], + "source": [ + "print(\"customer's order summary:\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "total_items = len(customer_order)\n", + "percentages = {3/5}\n", + "customer_order = (total_items, percentages)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n", + "0\n", + "{0.6}\n" + ] + } + ], + "source": [ + "print(customer_order)\n", + "print(total_items)\n", + "print(percentages)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for item in customer_order:\n", + " if inventory.get(item, 0) > 0:\n", + " inventory[intem] -=1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "update_display:\n" + ] + } + ], + "source": [ + "print(\"update_display:\")\n", + "for item, quantity in inventory.items():\n", + " print(f\"{item}: {quantity} left in stock\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -54,7 +213,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +227,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,