From 1015fb0f6da163a9d721a7d9f6d3e2e86b318ab5 Mon Sep 17 00:00:00 2001 From: Irma Fernandez Date: Thu, 4 Sep 2025 18:14:10 +0200 Subject: [PATCH] Lab data types extra done --- cfu-data-types.ipynb | 86 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 7 deletions(-) diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..f5be031 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,11 +49,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter your name: Irma\n", + "Enter your age (years): 49\n", + "Enter your address/city: Berlin\n", + "Enter your monthly salary (USD): 500\n", + "Enter your monthly expenses (USD): 200\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Irma, who is 49 years old, and lives in Berlin has 300.0 dollars left from her salary. It is False that she has more than 500 left\n" + ] + } + ], "source": [ - "# Your code here\n" + "# 1) Ask the user for their personal info (input() returns a string\n", + "name = input(\"Enter your name: \").strip()\n", + "age = int(input(\"Enter your age (years): \").strip())\n", + "address = input(\"Enter your address/city: \").strip()\n", + "salary = float(input(\"Enter your monthly salary (USD): \").strip())\n", + "expenses = float(input(\"Enter your monthly expenses (USD): \").strip())\n", + "\n", + "# 2) Compute remaining salary and round to one decimal\n", + "remaining_salary = round(salary - expenses, 1)\n", + "\n", + "# 3) Boolean indicating if remaining salary is >500\n", + "is_salary_good = remaining_salary >= 500\n", + "\n", + "print(f\"{name}, who is {age} years old, and lives in {address} has {remaining_salary} dollars left from her salary. It is {is_salary_good} that she has more than 500 left\")\n", + "\n" ] }, { @@ -102,12 +135,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Length of new string: 259\n", + "['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', 'python', 'is', 'awesome!']\n" + ] + } + ], "source": [ - "# Your code here\n" + "import string\n", + "#Original text\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", + "#1 remove punctuation an lowercase\n", + "clean_poem = poem.translate(str.maketrans('','', string.punctuation)).lower().replace(\"\\n\",\" \")\n", + "\n", + "#2 concatenate\n", + "new_string = clean_poem + \" python is awesome!\"\n", + "\n", + "#3 print the lenght\n", + "print(\"Length of new string:\", len(new_string))\n", + "\n", + "#4 Split into list of words\n", + "poem_list = new_string.split(\" \")\n", + "print(poem_list)\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -126,7 +198,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,