From b0dcf28efe7eaeb91bcf3bae6e9e27e72b1338dc Mon Sep 17 00:00:00 2001 From: Geraldine Date: Thu, 11 Sep 2025 18:51:57 +0200 Subject: [PATCH 1/4] Hi testing the changes --- your-code/main.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index de27676..7f85d55 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -13,7 +13,7 @@ "metadata": {}, "outputs": [], "source": [ - "words = ['play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']" + "words = ['Ironhack','Hello','testing','play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']" ] }, { From 19955e923a2a0991f3d12272547327333575e240 Mon Sep 17 00:00:00 2001 From: Geraldine Date: Thu, 11 Sep 2025 18:59:49 +0200 Subject: [PATCH 2/4] initial commit of the main notebook structure --- your-code/main.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 7f85d55..f121186 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -13,7 +13,7 @@ "metadata": {}, "outputs": [], "source": [ - "words = ['Ironhack','Hello','testing','play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']" + "words = ['Ironhack', 'Hello', 'testing', 'play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']" ] }, { From 5bc3f28369aadd55d2b160ce68939de4ee84cc6a Mon Sep 17 00:00:00 2001 From: Geraldine Date: Sat, 13 Sep 2025 14:29:31 +0200 Subject: [PATCH 3/4] for and if From a91508ce656c9b4c86cffa790a46f2317dd35260 Mon Sep 17 00:00:00 2001 From: Geraldine Date: Sat, 13 Sep 2025 14:53:42 +0200 Subject: [PATCH 4/4] for and if --- your-code/geraldine-main.ipynb | 458 +++++++++++++++++++++++++++++++++ 1 file changed, 458 insertions(+) create mode 100644 your-code/geraldine-main.ipynb diff --git a/your-code/geraldine-main.ipynb b/your-code/geraldine-main.ipynb new file mode 100644 index 0000000..7f3955a --- /dev/null +++ b/your-code/geraldine-main.ipynb @@ -0,0 +1,458 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Words" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "words = ['Hello', 'play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Print every word in upper case**" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HELLO\n", + "PLAY\n", + "FILLING\n", + "BAR\n", + "THEATRE\n", + "EASYGOING\n", + "DATE\n", + "LEAD\n", + "THAT\n", + "STORY\n", + "ISLAND\n" + ] + } + ], + "source": [ + "words = ['Hello', 'play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']\n", + "\n", + "for word in words:\n", + " print(word.upper())\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Create a new list containing only words with 5 or more letters**" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Hello', 'filling', 'theatre', 'easygoing', 'story', 'island']\n" + ] + } + ], + "source": [ + "words = ['Hello', 'play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']\n", + "\n", + "# Create a new list with only words that have 5 or more letters\n", + "long_words = [word for word in words if len(word) >= 5]\n", + "\n", + "print(long_words)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Print the first word starting with \"t\"**" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n" + ] + } + ], + "source": [ + "words = ['Hello', 'play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']\n", + "\n", + "for word in words:\n", + " if word.startswith(\"t\"):\n", + " print(word)\n", + " break # stop after the first match\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Numbers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Create a list containing the square of every number from 1 to 10**" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + ] + } + ], + "source": [ + "squares = [n**2 for n in range(1, 11)]\n", + "print(squares)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Print a list containing the square of every odd number from 1 to 10**" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 9, 25, 49, 81]\n" + ] + } + ], + "source": [ + "odd_squares = [n**2 for n in range(1, 11) if n % 2 != 0]\n", + "print(odd_squares)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Create a list with the squares of all multiples of 8 below 1000**" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[64, 256, 576, 1024, 1600, 2304, 3136, 4096, 5184, 6400, 7744, 9216, 10816, 12544, 14400, 16384, 18496, 20736, 23104, 25600, 28224, 30976, 33856, 36864, 40000, 43264, 46656, 50176, 53824, 57600, 61504, 65536, 69696, 73984, 78400, 82944, 87616, 92416, 97344, 102400, 107584, 112896, 118336, 123904, 129600, 135424, 141376, 147456, 153664, 160000, 166464, 173056, 179776, 186624, 193600, 200704, 207936, 215296, 222784, 230400, 238144, 246016, 254016, 262144, 270400, 278784, 287296, 295936, 304704, 313600, 322624, 331776, 341056, 350464, 360000, 369664, 379456, 389376, 399424, 409600, 419904, 430336, 440896, 451584, 462400, 473344, 484416, 495616, 506944, 518400, 529984, 541696, 553536, 565504, 577600, 589824, 602176, 614656, 627264, 640000, 652864, 665856, 678976, 692224, 705600, 719104, 732736, 746496, 760384, 774400, 788544, 802816, 817216, 831744, 846400, 861184, 876096, 891136, 906304, 921600, 937024, 952576, 968256, 984064]\n" + ] + } + ], + "source": [ + "squares_of_eights = [n**2 for n in range(8, 1000, 8)]\n", + "print(squares_of_eights)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## People" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "people = [\n", + " {\n", + " \"name\": \"Juan\",\n", + " \"age\": 34,\n", + " \"n_kids\": 2\n", + " },\n", + " {\n", + " \"name\": \"Pepe\",\n", + " \"age\": 27,\n", + " \"n_kids\": 0\n", + " },\n", + " {\n", + " \"name\": \"Sonia\",\n", + " \"age\": 41,\n", + " \"n_kids\": 1\n", + " },\n", + " {\n", + " \"name\": \"Lucía\",\n", + " \"age\": 22,\n", + " \"n_kids\": 2\n", + " },\n", + " {\n", + " \"name\": \"Leo\",\n", + " \"age\": 55,\n", + " \"n_kids\": 5\n", + " }\n", + "]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**How many people are there?**" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], + "source": [ + "people = [\n", + " {\n", + " \"name\": \"Juan\",\n", + " \"age\": 34,\n", + " \"n_kids\": 2\n", + " },\n", + " {\n", + " \"name\": \"Pepe\",\n", + " \"age\": 27,\n", + " \"n_kids\": 0\n", + " },\n", + " {\n", + " \"name\": \"Sonia\",\n", + " \"age\": 41,\n", + " \"n_kids\": 1\n", + " },\n", + " {\n", + " \"name\": \"Lucía\",\n", + " \"age\": 22,\n", + " \"n_kids\": 2\n", + " },\n", + " {\n", + " \"name\": \"Leo\",\n", + " \"age\": 55,\n", + " \"n_kids\": 5\n", + " }\n", + "]\n", + "print(len(people))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**How many people have kids**?" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of people with kids: 4\n" + ] + } + ], + "source": [ + "count_with_kids = sum(1 for person in people if person[\"n_kids\"] > 0)\n", + "\n", + "print(f\"Number of people with kids: {count_with_kids}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**How many kids do they have in total?**" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total number of kids: 10\n" + ] + } + ], + "source": [ + "total_kids = sum(person[\"n_kids\"] for person in people)\n", + "\n", + "print(f\"Total number of kids: {total_kids}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**In a year's time, names ending with \"a\" will have an extra kid. Create a list of dictionaries with people's info in a year's time**" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "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": [ + "people_next_year = []\n", + "\n", + "for person in people:\n", + " updated_person = person.copy() # make a copy of the dictionary\n", + " updated_person[\"age\"] += 1 # everyone gets 1 year older\n", + " if person[\"name\"].endswith(\"a\"): # if name ends with \"a\"\n", + " updated_person[\"n_kids\"] += 1 # add 1 child\n", + " people_next_year.append(updated_person)\n", + "\n", + "print(people_next_year)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total number of kids in a year's time: 12\n" + ] + } + ], + "source": [ + "total_kids_next_year = sum(p[\"n_kids\"] for p in people_next_year)\n", + "\n", + "print(f\"Total number of kids in a year's time: {total_kids_next_year}\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.5" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": true + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}