From a6c6c171cf92435120fac5eda3bd5cd1f7bb63c4 Mon Sep 17 00:00:00 2001 From: kep1n Date: Thu, 11 Sep 2025 18:44:30 +0200 Subject: [PATCH 1/2] Changes in ipynb file --- your-code/main.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index de27676..a034db6 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -25,11 +25,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "words_upper = [el.upper() for el in words]" ] }, { @@ -242,7 +242,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.0" }, "toc": { "base_numbering": 1, From 955dfca5d3a76f4c118dfd5c204063b0e32bf316 Mon Sep 17 00:00:00 2001 From: kep1n Date: Sat, 13 Sep 2025 12:54:33 +0200 Subject: [PATCH 2/2] Solutions for Lab | for loops and if conditions (week1 day2) --- your-code/main.ipynb | 194 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 160 insertions(+), 34 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index a034db6..f05fb7d 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "NOTE: I used list comprehensions in most of the cases even if we haven't seen them yet. Hope it's not a problem." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -27,9 +34,27 @@ "cell_type": "code", "execution_count": 3, "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": [ - "words_upper = [el.upper() for el in words]" + "for word in words:\n", + " print(word.upper())" ] }, { @@ -41,11 +66,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['filling', 'theatre', 'easygoing', 'story', 'island']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "words5_and_above = [word for word in words if len(word) >= 5]\n", + "words5_and_above" ] }, { @@ -57,11 +94,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n" + ] + } + ], "source": [ - "# your code here" + "for word in words:\n", + " if word[0] == 't':\n", + " print(word)\n", + " break" ] }, { @@ -80,11 +128,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "squares = [i**2 for i in range(1, 11)]\n", + "squares" ] }, { @@ -96,11 +156,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 9, 25, 49, 81]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "squares_odd = [i**2 for i in range(1, 11) if i%2 != 0]\n", + "squares_odd" ] }, { @@ -116,7 +188,7 @@ "metadata": {}, "outputs": [], "source": [ - "# your code here" + "squares_below_thousand = [i**2 for i in range(1000) if i%8 == 0]" ] }, { @@ -128,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -170,11 +242,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are 5 of them\n" + ] + } + ], "source": [ - "# your code here" + "print(f'There are {len(people)} of them')" ] }, { @@ -186,11 +266,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4 people have kids\n" + ] + } + ], "source": [ - "# your code here" + "number_kids = len([person for person in people if person['n_kids'] > 0])\n", + "print(f'{number_kids} people have kids')" ] }, { @@ -202,11 +291,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "sum([person['n_kids'] for person in people])" ] }, { @@ -218,17 +318,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Congrats Sonia! ;-)!\n", + "Congrats Lucía! ;-)!\n" + ] + }, + { + "data": { + "text/plain": [ + "[{'name': 'Juan', 'age': 34, 'n_kids': 2},\n", + " {'name': 'Pepe', 'age': 27, 'n_kids': 0},\n", + " {'name': 'Sonia', 'age': 41, 'n_kids': 2},\n", + " {'name': 'Lucía', 'age': 22, 'n_kids': 3},\n", + " {'name': 'Leo', 'age': 55, 'n_kids': 5}]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "people_after_year = []\n", + "for person in people:\n", + " # create new object to avoid changes in original list of persons\n", + " temp_data = dict(person)\n", + " if person['name'][-1].lower() == 'a':\n", + " temp_data['n_kids'] += 1\n", + " print(f'Congrats {person['name']}! ;-)!')\n", + " people_after_year.append(temp_data)\n", + "people_after_year" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "ironhack", "language": "python", "name": "python3" }, @@ -285,11 +416,6 @@ "_Feature" ], "window_display": false - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } } }, "nbformat": 4,