diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..a1e7390 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,11 +49,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lotje, who is 38 years old, and lives in Dokter Kittenstraat 5 has 2441.0 dollars left from her salary after expenses. It is True that she has more than $500 left.\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Ask for user inputs (input() returns strings)\n", + "name = input(\"Enter your name: \").strip()\n", + "age = int(input(\"Enter your age: \").strip()) # cast to int\n", + "address = input(\"Enter your address: \").strip()\n", + "salary = float(input(\"Enter your monthly salary: \").strip()) # cast to float\n", + "expenses = float(input(\"Enter your monthly expenses: \").strip())# cast to float\n", + "\n", + "# Calculate and round remaining salary\n", + "remaining_salary = round(salary - expenses, 1) # one decimal\n", + "\n", + "# Boolean indicating if at least $500 remains\n", + "is_salary_good = remaining_salary >= 500\n", + "\n", + "# Print formatted message\n", + "print(f\"{name}, who is {age} years old, and lives in {address} has \"\n", + " f\"{remaining_salary:.1f} dollars left from her salary after expenses. \"\n", + " f\"It is {is_salary_good} that she has more than $500 left.\")\n" ] }, { @@ -85,7 +109,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -102,17 +126,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Length of new string: 259\n", + "['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": [ - "# Your code here\n" + "# Step 1: Clean text → lowercase + remove punctuation\n", + "import string\n", + "poem_cleaned = poem.lower().translate(str.maketrans('', '', string.punctuation))\n", + "\n", + "# Step 2: Concatenate with \"python is awesome!\"\n", + "new_poem = poem_cleaned + \" python is awesome!\"\n", + "\n", + "# Step 3: Print length of the new string\n", + "print(\"Length of new string:\", len(new_poem))\n", + "\n", + "# Step 4: Split into list using space delimiter\n", + "poem_list = new_poem.split(\" \")\n", + "print(poem_list)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -126,7 +171,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,