From 6e4dbabea8e90a8c80459ca898d6a3920012f1ef Mon Sep 17 00:00:00 2001 From: MonicaFernandezM Date: Mon, 12 Jan 2026 16:48:20 +0100 Subject: [PATCH 1/2] solution-data-types --- cfu-data-types.ipynb | 184 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 176 insertions(+), 8 deletions(-) diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..4606f9e 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,11 +49,99 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "name = input(\"Enter your name: \")\n", + "age = int(input(\"Enter your age: \"))\n", + "address = input(\"Enter your address: \")\n", + "salary = float(input(\"Enter your salary: \"))\n", + "expenses = float(input(\"Enter your expenses\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\n" + ] + } + ], + "source": [ + "#Data type\n", + "print(type(age))\n", + "print(type(salary))\n", + "print(type(expenses))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1108.5" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "remaining_salary = salary - expenses\n", + "remaining_salary = round(remaining_salary, 1)\n", + "remaining_salary" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "is_salary_good = remaining_salary >= 500\n", + "is_salary_good" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Maya, who is 27 years old, and lives in Madrid has 1108.5 dollars left from her salary after expenses. It is True that she has more than $500 left.\n" + ] + } + ], + "source": [ + "print(f\"{name}, who is {age} years old, and lives in {address} has {remaining_salary} dollars left from her salary after expenses. \\\n", + " It is {is_salary_good} that she has more than $500 left.\")" ] }, { @@ -85,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -102,17 +190,97 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'some say the world will end in fire\\nsome say in ice\\nfrom what i ve tasted of desire\\ni hold with those who favor fire\\nbut if it had to perish twice\\ni think i know enough of hate\\nto say that for destruction ice\\nis also great\\nand would suffice'" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import string \n", + "#removes the punctuation and leaves everything in lowercase\n", + "clean_poem = poem.translate(str.maketrans(\"’\", \" \", string.punctuation)).lower()\n", + "clean_poem" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'some say the world will end in fire\\nsome say in ice\\nfrom what i ve tasted of desire\\ni hold with those who favor fire\\nbut if it had to perish twice\\ni think i know enough of hate\\nto say that for destruction ice\\nis also great\\nand would suffice python is awesome!'" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Concatenate the resulting with the string \"python is awesome!\"\n", + "result_clean = clean_poem + \" \" +\"python is awesome!\"\n", + "result_clean" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "259\n" + ] + } + ], "source": [ - "# Your code here\n" + "#Len of the result_clean\n", + "print(len(result_clean))" ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire\\nsome', 'say', 'in', 'ice\\nfrom', 'what', 'i', 've', 'tasted', 'of', 'desire\\ni', 'hold', 'with', 'those', 'who', 'favor', 'fire\\nbut', 'if', 'it', 'had', 'to', 'perish', 'twice\\ni', 'think', 'i', 'know', 'enough', 'of', 'hate\\nto', 'say', 'that', 'for', 'destruction', 'ice\\nis', 'also', 'great\\nand', 'would', 'suffice', 'python', 'is', 'awesome!']\n" + ] + } + ], + "source": [ + "#split the result_clean using the space delimitator \n", + "poem_list = result_clean.split(\" \")\n", + "print(poem_list)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -126,7 +294,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.10.2" } }, "nbformat": 4, From 7a87feff908c862b3fe929155fe2f06d935053db Mon Sep 17 00:00:00 2001 From: MonicaFernandezM Date: Mon, 12 Jan 2026 17:02:27 +0100 Subject: [PATCH 2/2] finish-data-types --- cfu-data-types.ipynb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index 4606f9e..1adcbfd 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -173,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -190,39 +190,39 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'some say the world will end in fire\\nsome say in ice\\nfrom what i ve tasted of desire\\ni hold with those who favor fire\\nbut if it had to perish twice\\ni think i know enough of hate\\nto say that for destruction ice\\nis also great\\nand would suffice'" + "'some say the world will end in fire\\nsome say in ice\\nfrom what ive tasted of desire\\ni hold with those who favor fire\\nbut if it had to perish twice\\ni think i know enough of hate\\nto say that for destruction ice\\nis also great\\nand would suffice'" ] }, - "execution_count": 44, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "import string \n", + "import re\n", "#removes the punctuation and leaves everything in lowercase\n", - "clean_poem = poem.translate(str.maketrans(\"’\", \" \", string.punctuation)).lower()\n", + "clean_poem = re.sub(r\"[^a-zA-Z0-9\\s]\",\"\" \"\", poem).lower()\n", "clean_poem" ] }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'some say the world will end in fire\\nsome say in ice\\nfrom what i ve tasted of desire\\ni hold with those who favor fire\\nbut if it had to perish twice\\ni think i know enough of hate\\nto say that for destruction ice\\nis also great\\nand would suffice python is awesome!'" + "'some say the world will end in fire\\nsome say in ice\\nfrom what ive tasted of desire\\ni hold with those who favor fire\\nbut if it had to perish twice\\ni think i know enough of hate\\nto say that for destruction ice\\nis also great\\nand would suffice python is awesome!'" ] }, - "execution_count": 45, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -235,14 +235,14 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "259\n" + "258\n" ] } ], @@ -253,14 +253,14 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire\\nsome', 'say', 'in', 'ice\\nfrom', 'what', 'i', 've', 'tasted', 'of', 'desire\\ni', 'hold', 'with', 'those', 'who', 'favor', 'fire\\nbut', 'if', 'it', 'had', 'to', 'perish', 'twice\\ni', 'think', 'i', 'know', 'enough', 'of', 'hate\\nto', 'say', 'that', 'for', 'destruction', 'ice\\nis', 'also', 'great\\nand', 'would', 'suffice', 'python', 'is', 'awesome!']\n" + "['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire\\nsome', 'say', 'in', 'ice\\nfrom', 'what', 'ive', 'tasted', 'of', 'desire\\ni', 'hold', 'with', 'those', 'who', 'favor', 'fire\\nbut', 'if', 'it', 'had', 'to', 'perish', 'twice\\ni', 'think', 'i', 'know', 'enough', 'of', 'hate\\nto', 'say', 'that', 'for', 'destruction', 'ice\\nis', 'also', 'great\\nand', 'would', 'suffice', 'python', 'is', 'awesome!']\n" ] } ],