From c5f066f3be89a05cb89fc0e3fec423ba88f1fa6b Mon Sep 17 00:00:00 2001 From: Eylin Date: Mon, 26 Jan 2026 14:58:03 +0100 Subject: [PATCH] Add data types extra --- cfu-data-types.ipynb | 206 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 198 insertions(+), 8 deletions(-) diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..1dd9e42 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,11 +49,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ - "# 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\"))\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "remaining_salary = salary - expenses\n", + "is_salary_good = remaining_salary >= 500" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Eylin who is 20 years old, and lives in Germany, has 100.0 dollars left from her salary after expenses. It is False that she has more than $500 left.\n" + ] + } + ], + "source": [ + "description = f\"{name} who is {age} years old, and lives in {address}, has {remaining_salary} dollars left from her salary after expenses. It is {is_salary_good} that she has more than $500 left.\"\n", + "print(description)\n" ] }, { @@ -85,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ @@ -102,17 +140,169 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "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" + ] + } + ], + "source": [ + "import string\n", + "new_poem = poem.translate(str.maketrans('', '' , string.punctuation))\n", + "print(new_poem)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "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'" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_poem_lowercase = new_poem.lower()\n", + "new_poem_lowercase" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "python is awesome 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" + ] + } + ], + "source": [ + "poem2 = f\"python is awesome {new_poem_lowercase}\"\n", + "print(poem2)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "258" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "poem3 = len(poem2)\n", + "poem3" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['python',\n", + " 'is',\n", + " 'awesome',\n", + " 'some',\n", + " 'say',\n", + " 'the',\n", + " 'world',\n", + " 'will',\n", + " 'end',\n", + " 'in',\n", + " 'fire\\nsome',\n", + " 'say',\n", + " 'in',\n", + " 'ice\\nfrom',\n", + " 'what',\n", + " 'i’ve',\n", + " 'tasted',\n", + " 'of',\n", + " 'desire\\ni',\n", + " 'hold',\n", + " 'with',\n", + " 'those',\n", + " 'who',\n", + " 'favor',\n", + " 'fire\\nbut',\n", + " 'if',\n", + " 'it',\n", + " 'had',\n", + " 'to',\n", + " 'perish',\n", + " 'twice\\ni',\n", + " 'think',\n", + " 'i',\n", + " 'know',\n", + " 'enough',\n", + " 'of',\n", + " 'hate\\nto',\n", + " 'say',\n", + " 'that',\n", + " 'for',\n", + " 'destruction',\n", + " 'ice\\nis',\n", + " 'also',\n", + " 'great\\nand',\n", + " 'would',\n", + " 'suffice']" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "poem_list = poem2.split(\" \")\n", + "poem_list" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -126,7 +316,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,