From 855e7596c29d7b6999a72b208169ab68e648ec68 Mon Sep 17 00:00:00 2001 From: Anirudh-Unni Date: Tue, 22 Jul 2025 17:34:02 +0200 Subject: [PATCH] Day2Lab final version --- your-code/main.ipynb | 195 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 160 insertions(+), 35 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index de27676..5fcb0a5 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -25,11 +25,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PLAY\n", + "FILLING\n", + "BAR\n", + "THEATRE\n", + "EASYGOING\n", + "DATE\n", + "LEAD\n", + "THAT\n", + "STORY\n", + "ISLAND\n" + ] + } + ], "source": [ - "# your code here" + "for items in words:\n", + " print(items.upper())" ] }, { @@ -41,11 +59,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['filling', 'theatre', 'easygoing', 'story', 'island']" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "long_words = [i for i in words if len(i) >=5]\n", + "long_words" ] }, { @@ -59,9 +89,20 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n", + "that\n" + ] + } + ], "source": [ - "# your code here" + "for i in words:\n", + " if i.startswith('t'): # This will check if each word starts with 't'\n", + " print(i)" ] }, { @@ -80,11 +121,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "square_list = [i**2 for i in range(1,11)]\n", + "square_list" ] }, { @@ -96,11 +149,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 9, 25, 49, 81]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "square_list = [i**2 for i in range(1,11,2)]\n", + "square_list" ] }, { @@ -112,11 +177,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "64\n", + "256\n", + "576\n" + ] + } + ], "source": [ - "# your code here" + "square_list = [i**2 for i in range(0,1001,8)]\n", + "for i in square_list:\n", + " if i<1000:\n", + " print(i)" ] }, { @@ -172,9 +251,18 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], "source": [ - "# your code here" + "\n", + "print(len(people))" ] }, { @@ -188,9 +276,22 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Juan\n", + "Sonia\n", + "Lucía\n", + "Leo\n" + ] + } + ], "source": [ - "# your code here" + "for kpeople in people:\n", + " if kpeople[\"n_kids\"] > 0:\n", + " print(kpeople[\"name\"])" ] }, { @@ -202,11 +303,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n" + ] + } + ], "source": [ - "# your code here" + "total_kids = 0\n", + "for person in people:\n", + " \n", + " total_kids += person[\"n_kids\"]\n", + "print(total_kids)\n" ] }, { @@ -218,17 +331,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'name': 'Juan', 'age': 35, 'n_kids': 2}, {'name': 'Pepe', 'age': 28, 'n_kids': 0}, {'name': 'Sonia', 'age': 42, 'n_kids': 2}, {'name': 'Lucía', 'age': 23, 'n_kids': 3}, {'name': 'Leo', 'age': 56, 'n_kids': 5}]\n" + ] + } + ], "source": [ - "# your code here" + "people_in_a_year = [\n", + " {\n", + " \"name\": person[\"name\"],\n", + " \"age\": person[\"age\"] + 1,\n", + " \"n_kids\": person[\"n_kids\"] + 1 if person[\"name\"].endswith('a') else person[\"n_kids\"]\n", + " }\n", + " for person in people\n", + "]\n", + "\n", + "print(people_in_a_year)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -242,7 +372,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" }, "toc": { "base_numbering": 1, @@ -285,11 +415,6 @@ "_Feature" ], "window_display": false - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } } }, "nbformat": 4,