From 7fe36159903990b6f83596131d09c9e19e02c06d Mon Sep 17 00:00:00 2001 From: Jan Noel Vero Date: Tue, 21 Jul 2026 22:43:08 +0200 Subject: [PATCH] Complete Data Types Extra Lab --- cfu-data-types.ipynb | 146 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 139 insertions(+), 7 deletions(-) diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..a82a08b 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,11 +49,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter your name: Jan\n", + "Enter your age: 39\n", + "Enter your address: Berlin\n", + "Enter your salary: 6000\n", + "Enter your total expenses: 4000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Jan, who is 39 years old, and lives in Berlin, has 2000.0 dollars left from her salary after expenses. It is True that she has more than $500 left.\n" + ] + } + ], + "source": [ + "name = input(\"Enter your name: \")\n", + "\n", + "age = int(input(\"Enter your age: \"))\n", + "\n", + "address = input(\"Enter your address: \")\n", + "\n", + "salary = float(input(\"Enter your salary: \"))\n", + "\n", + "expenses = float(input(\"Enter your total expenses: \"))\n", + "\n", + "remaining_salary = salary - expenses\n", + "\n", + "remaining_salary = round(remaining_salary, 1)\n", + "\n", + "is_salary_good = remaining_salary >= 500\n", + "\n", + "print(\n", + " f\"{name}, who is {age} years old, and lives in {address}, \"\n", + " f\"has {remaining_salary} dollars left from her salary after expenses. \"\n", + " f\"It is {is_salary_good} that she has more than $500 left.\"\n", + ")# Your code here\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "remaining_salary = salary - expenses" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "is_salary_good = remaining_salary >= 500" ] }, { @@ -85,7 +142,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -102,12 +159,87 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "some say the world will end in fire some say in ice from what ive 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 python is awesome!\n", + "258\n", + "['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'ive', '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', 'python', 'is', 'awesome!']\n" + ] + } + ], "source": [ - "# Your code here\n" + "poem = \"\"\"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", + "\n", + "clean_poem = (\n", + " poem.lower()\n", + " .replace(\",\", \"\")\n", + " .replace(\".\", \"\")\n", + " .replace(\"’\", \"\")\n", + " .replace(\"\\n\", \" \")\n", + ")\n", + "\n", + "new_poem = clean_poem + \" python is awesome!\"\n", + "\n", + "print(new_poem)\n", + "print(len(new_poem))\n", + "\n", + "poem_list = new_poem.split(\" \")\n", + "\n", + "print(poem_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "258\n", + "['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'ive', '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', 'python', 'is', 'awesome!']\n" + ] + } + ], + "source": [ + "clean_poem = (\n", + " poem\n", + " .lower()\n", + " .replace(\",\", \"\")\n", + " .replace(\".\", \"\")\n", + " .replace(\"’\", \"\")\n", + " .replace(\"\\n\", \" \")\n", + ")\n", + "\n", + "new_poem = clean_poem + \" python is awesome!\"\n", + "\n", + "print(len(new_poem))\n", + "\n", + "poem_list = new_poem.split(\" \")\n", + "\n", + "print(poem_list)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -126,7 +258,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.14" } }, "nbformat": 4,