diff --git a/lab-control-flow-en.ipynb b/lab-control-flow-en.ipynb deleted file mode 100644 index 01a1479..0000000 --- a/lab-control-flow-en.ipynb +++ /dev/null @@ -1,435 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Words" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "words = ['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": 3, - "metadata": {}, - "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": [ - "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": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['filling', 'theatre', 'easygoing', 'story', 'island']\n" - ] - } - ], - "source": [ - "five_letters = []\n", - "\n", - "for word in words:\n", - " if len(word) >= 5:\n", - " five_letters.append(word)\n", - "\n", - "print(five_letters)\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Print the first word starting with \"t\"**" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "theatre\n" - ] - } - ], - "source": [ - "for word in words:\n", - " if word.startswith('t'):\n", - " print(word)\n", - " break" - ] - }, - { - "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": 6, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" - ] - } - ], - "source": [ - "square=[]\n", - "\n", - "for numbers in range(1, 11):\n", - " square.append(numbers**2)\n", - "\n", - "print(square)\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": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 9, 25, 49, 81]\n" - ] - } - ], - "source": [ - "square_odds=[]\n", - "\n", - "for numbers in range(1, 11):\n", - " if numbers % 2 != 0:\n", - " square_odds.append(numbers**2)\n", - "\n", - "print(square_odds)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Create a list with the squares of all multiples of 8 below 1000**" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392, 400, 408, 416, 424, 432, 440, 448, 456, 464, 472, 480, 488, 496, 504, 512, 520, 528, 536, 544, 552, 560, 568, 576, 584, 592, 600, 608, 616, 624, 632, 640, 648, 656, 664, 672, 680, 688, 696, 704, 712, 720, 728, 736, 744, 752, 760, 768, 776, 784, 792, 800, 808, 816, 824, 832, 840, 848, 856, 864, 872, 880, 888, 896, 904, 912, 920, 928, 936, 944, 952, 960, 968, 976, 984, 992, 1000]\n" - ] - } - ], - "source": [ - "square_eight=[]\n", - "\n", - "for numbers in range(1, 1001):\n", - " if numbers % 8 == 0:\n", - " square_eight.append(numbers)\n", - "\n", - "print(square_eight)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## People" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "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", - "]" - ] - }, - { - "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": [ - "number_of_people = len(people)\n", - "\n", - "print(number_of_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": [ - "4\n" - ] - } - ], - "source": [ - "kids = 0\n", - "\n", - "for person in people:\n", - " if person[\"n_kids\"] > 0:\n", - " kids += 1\n", - "\n", - "print(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": [ - "Name: Juan, Number of Kids: 2\n", - "Name: Sonia, Number of Kids: 1\n", - "Name: Lucía, Number of Kids: 2\n", - "Name: Leo, Number of Kids: 5\n", - "The total amount of kids is: 10\n" - ] - } - ], - "source": [ - "total_kids = 0\n", - "\n", - "for person in people:\n", - " if person[\"n_kids\"] > 0:\n", - " print(f\"Name: {person['name']}, Number of Kids: {person['n_kids']}\")\n", - " total_kids += person[\"n_kids\"]\n", - "\n", - "print(\"The total amount of kids is: \", total_kids)\n", - " \n", - " \n" - ] - }, - { - "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": [], - "source": [ - "people_in_a_year = []\n", - "\n", - "for person in people:\n", - " people_in_a_year.append({\n", - " \"name\": person[\"name\"],\n", - " \"age\": person[\"age\"],\n", - " \"n_kids\": person[\"n_kids\"]\n", - " })\n", - " person[\"age\"] += 1\n", - "\n", - "for person in people:\n", - " if person[\"name\"].endswith('a'):\n", - " person[\"n_kids\"] += 1\n", - " " - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.0" - }, - "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 -}