From dd663dfa5e7f6ec8b215eb220bce42cb5586227b Mon Sep 17 00:00:00 2001 From: Ghonaim32 Date: Tue, 7 Oct 2025 15:10:47 +0200 Subject: [PATCH] Solved lab --- lab-python-data-structures.ipynb | 189 ++++++++++++++++++++++++++++++- 1 file changed, 187 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..e907eb80 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,196 @@ "\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": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 65, 'mug': 42, 'hat': 34, 'book': 20, 'keychain': 21}\n" + ] + } + ], + "source": [ + "t_shirt=int(input(\"Please enter the numbers of t-shirts: \"))\n", + "mug=int(input(\"Please enter the number of mugs: \"))\n", + "hat=int(input(\"Please enter the number of hats: \"))\n", + "book=int(input(\"Please enter the number of books: \"))\n", + "keychain=int(input(\"Please enter the number of keychains: \"))\n", + "\n", + "inventory = {}\n", + "inventory[\"t-shirt\"]=t_shirt\n", + "inventory[\"mug\"]=mug\n", + "inventory[\"hat\"]=hat\n", + "inventory[\"book\"]=book\n", + "inventory[\"keychain\"]=keychain\n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "customers_orders = {\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"}\n", + "print(type(customer_orders))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product added to cart\n", + "Product added to cart\n", + "Product added to cart\n", + "{'mug', 't-shirt'}\n" + ] + } + ], + "source": [ + "for i in range(3):\n", + " product = input(\"Enter the name of a product you want to order: \")\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " print(\"Product added to cart\")\n", + " else:\n", + " print(\"Product not in list\")\n", + "\n", + "print(customer_orders)\n", + "\n", + "# this is not working " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "0.00010989010989010989\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "print(total_products_ordered)\n", + "\n", + "percentage_ordered = len(customer_orders)/(sum(inventory.values())*100)\n", + "print(percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "order_status = (\"total_products_ordered\", \"percentage_ordered\")\n", + "print(type(order_status))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 2\n", + "Pecentage of Products Ordered: 0.00010989010989010989%\n" + ] + } + ], + "source": [ + "print(\"Order Statistics\"+\":\")\n", + "print(\"Total Products Ordered\"+\": \"+ str(total_products_ordered))\n", + "print(\"Pecentage of Products Ordered\"+\": \"+ str(percentage_ordered)+\"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 65, 'mug': 42, 'hat': 34, 'book': 20, 'keychain': 21}\n", + "t-shirt 64\n", + "mug 41\n", + "hat 33\n", + "book 19\n", + "keychain 20\n" + ] + } + ], + "source": [ + "print(inventory)\n", + "for key in inventory:\n", + " inventory[key] -= 1\n", + "\n", + "for key, value in inventory.items():\n", + " print(key,value)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +253,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.7" } }, "nbformat": 4,