From 97b45a30ccdb69b491a005ed85b36ea147597859 Mon Sep 17 00:00:00 2001 From: dianayule Date: Sun, 10 May 2026 10:02:49 +0200 Subject: [PATCH 1/2] Lab done --- cfu-data-types.ipynb | 91 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 10 deletions(-) diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..6153ce5 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,11 +49,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter your name: asdf\n", + "Enter your age in numbers: 23\n", + "Enter your address: dfasdf\n", + "Enter your salary in numbers: 234\n", + "Enter the total amount of your expenses in numbers: 34\n" + ] + } + ], + "source": [ + "# 1. prompt the user to enter their personal information such as name, age, address, salary, \n", + "#and expenses\n", + "\n", + "name= input(\"Enter your name:\")\n", + "age= int(input(\"Enter your age in numbers:\"))\n", + "address=input(\"Enter your address:\")\n", + "salary= float(input(\"Enter your salary in numbers:\"))\n", + "expenses= float(input(\"Enter the total amount of your expenses in numbers:\"))\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It is False that the money you have left is >=500\n" + ] + } + ], "source": [ - "# Your code here\n" + "#Use a boolean variable to indicate whether the remaining salary is greater than or equal to 500.\n", + "check= lambda salary, expenses: salary-expenses>=500\n", + "print(f\"It is {check(salary,expenses)} that the money you have left is >=500\")\n", + "\n" ] }, { @@ -85,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -102,19 +143,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Some say the world will end in fire python is awesome\n", + "Some say in ice python is awesome\n", + "From what I’ve tasted of desire\n", + "I hold with those who favor fire python is awesome\n", + "But if it had to perish twice python is awesome\n", + "I think I know enough of hate\n", + "To say that for destruction ice\n", + "Is also great\n", + "And would suffice python is awesome\n", + "['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'python', 'is', 'awesome', 'Some', 'say', 'in', 'ice', 'python', 'is', 'awesome', 'From', 'what', 'I’ve', 'tasted', 'of', 'desire', 'I', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'python', 'is', 'awesome', 'But', 'if', 'it', 'had', 'to', 'perish', 'twice', 'python', 'is', 'awesome', 'I', 'think', 'I', 'know', 'enough', 'of', 'hate', 'To', 'say', 'that', 'for', 'destruction', 'ice', 'Is', 'also', 'great', 'And', 'would', 'suffice', 'python', 'is', 'awesome']\n" + ] + } + ], "source": [ - "# Your code here\n" + "# removes the punctuation and leaves everything in lowercase\n", + "new_poem=poem.replace(\",\",\" python is awesome\").replace(\".\",\" python is awesome\")\n", + "len(new_poem)\n", + "print(new_poem)\n", + "poem_list=[word for word in new_poem.split()]\n", + "len(poem_list)\n", + "print(poem_list)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -126,7 +197,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4, From e09048d89d8057bf85f23542f3c842310648fbf8 Mon Sep 17 00:00:00 2001 From: dianayule Date: Sun, 10 May 2026 10:17:48 +0200 Subject: [PATCH 2/2] Lab corrected --- cfu-data-types.ipynb | 57 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index 6153ce5..5626972 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,18 +49,18 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Enter your name: asdf\n", - "Enter your age in numbers: 23\n", - "Enter your address: dfasdf\n", - "Enter your salary in numbers: 234\n", - "Enter the total amount of your expenses in numbers: 34\n" + "Enter your name: pailo\n", + "Enter your age in numbers: 34\n", + "Enter your address: apdsofij 343 asdf\n", + "Enter your salary in numbers: 400\n", + "Enter the total amount of your expenses in numbers: 600\n" ] } ], @@ -71,29 +71,30 @@ "name= input(\"Enter your name:\")\n", "age= int(input(\"Enter your age in numbers:\"))\n", "address=input(\"Enter your address:\")\n", - "salary= float(input(\"Enter your salary in numbers:\"))\n", - "expenses= float(input(\"Enter the total amount of your expenses in numbers:\"))\n", + "salary= round(float(input(\"Enter your salary in numbers:\")),1)\n", + "expenses= round(float(input(\"Enter the total amount of your expenses in numbers:\")),1)\n", + "remaining_salary=salary-expenses\n", "\n", "\n" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "It is False that the money you have left is >=500\n" + "Hey pailo, who is 34 years old, and lives in apdsofij 343 asdf has -200.0 dollars left from her salary after expenses. It is False that she has more than $500 left.It is False that the money you have left is >=500\n" ] } ], "source": [ "#Use a boolean variable to indicate whether the remaining salary is greater than or equal to 500.\n", - "check= lambda salary, expenses: salary-expenses>=500\n", - "print(f\"It is {check(salary,expenses)} that the money you have left is >=500\")\n", + "check= remaining_salary>=500\n", + "print(f\"Hey {name}, who is {age} years old, and lives in {address} has {remaining_salary} dollars left from her salary after expenses. It is {check} that she has more than $500 left.It is {check} that the money you have left is >=500\")\n", "\n" ] }, @@ -143,33 +144,33 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 43, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Some say the world will end in fire python is awesome\n", - "Some say in ice python is awesome\n", - "From what I’ve tasted of desire\n", - "I hold with those who favor fire python is awesome\n", - "But if it had to perish twice python is awesome\n", - "I think I know enough of hate\n", - "To say that for destruction ice\n", - "Is also great\n", - "And would suffice python is awesome\n", - "['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'python', 'is', 'awesome', 'Some', 'say', 'in', 'ice', 'python', 'is', 'awesome', 'From', 'what', 'I’ve', 'tasted', 'of', 'desire', 'I', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'python', 'is', 'awesome', 'But', 'if', 'it', 'had', 'to', 'perish', 'twice', 'python', 'is', 'awesome', 'I', 'think', 'I', 'know', 'enough', 'of', 'hate', 'To', 'say', 'that', 'for', 'destruction', 'ice', 'Is', 'also', 'great', 'And', 'would', 'suffice', 'python', 'is', 'awesome']\n" + "some say the world will end in fire \n", + "some say in ice \n", + "from what i’ve tasted of desire\n", + "i hold with those who favor fire \n", + "but if it had to perish twice \n", + "i think i know enough of hate\n", + "to say that for destruction ice\n", + "is also great\n", + "and would suffice \n", + "245\n", + "['psome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'ysome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'tsome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'hsome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'osome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'nsome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'isome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'ssome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'asome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'wsome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'esome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'ssome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'osome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'msome', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice', 'e']\n" ] } ], "source": [ "# removes the punctuation and leaves everything in lowercase\n", - "new_poem=poem.replace(\",\",\" python is awesome\").replace(\".\",\" python is awesome\")\n", - "len(new_poem)\n", - "print(new_poem)\n", - "poem_list=[word for word in new_poem.split()]\n", - "len(poem_list)\n", + "new_poem=poem.replace(\",\",\" \").replace(\".\",\" \").lower()\n", + "new_poem= new_poem+ \"python is awesome\n", + "print(len(new_poem))\n", + "new_poem.split()\n", "print(poem_list)" ] },