From f5c52ceceb3b7b1e6371a17a5592c958837974e1 Mon Sep 17 00:00:00 2001 From: Julian Fernandes Date: Fri, 16 Jan 2026 08:54:16 +0100 Subject: [PATCH] julian lab done --- cfu-data-types.ipynb | 123 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 116 insertions(+), 7 deletions(-) diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..bbfe0d2 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -51,9 +51,72 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "julian, who is 50 years old, and lives in berlin has €30000.0 left from his/her salary after expenses. It is True that she has more than $500 left.\n", + "sara, who is 60 years old, and lives in paris has €40000.0 left from his/her salary after expenses. It is True that she has more than $500 left.\n" + ] + }, + { + "data": { + "text/plain": [ + "{0: {'name': 'julian',\n", + " 'age': 50,\n", + " 'city': 'berlin',\n", + " 'remaining_salary': 30000.0,\n", + " 'is_salary_good': True},\n", + " 1: {'name': 'sara',\n", + " 'age': 60,\n", + " 'city': 'paris',\n", + " 'remaining_salary': 40000.0,\n", + " 'is_salary_good': True}}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "#creating an empty dictionary\n", + "people_data = {}\n", + "\n", + "for i in range(2):\n", + " name = input(\"Enter you name:\")\n", + " age = int(input(\"Enter you age:\"))\n", + " city = (input(\"Enter you city:\"))\n", + " salary = float(input(\"Enter your salary:\"))\n", + " expenses = float(input(\"Enter your expense\"))\n", + "\n", + "\n", + "#do the required calculations \n", + " remaining_salary = round(salary - expenses, 1)\n", + " is_salary_good = bool(remaining_salary >= 500)\n", + "\n", + " print(f\"{name}, who is {age} years old, and lives in {city} has €{remaining_salary} left from his/her salary after expenses. It is {is_salary_good} that she has more than $500 left.\")\n", + "\n", + "\n", + "\n", + "#saving the info to the dictionary and appending everytime\n", + " personal_details = {\n", + " \"name\": name,\n", + " \"age\": age,\n", + " \"city\": city,\n", + " \"remaining_salary\": remaining_salary,\n", + " \"is_salary_good\": is_salary_good\n", + " }\n", + "\n", + " people_data[i] = personal_details #is this correct, works but tried append and then googled and llm but is there another way?\n", + "\n", + "\n", + "\n", + "people_data\n", + "\n" ] }, { @@ -102,17 +165,63 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\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", + "python is awesome\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "import string\n", + "\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", + "\n", + "#lower()\tConverts a string into lower case, this works \n", + "poem_lower = poem.lower()\n", + "\n", + "\n", + "#added the extra sentence\n", + "new_string = poem_lower + \"\\npython is awesome\" #update poem with the new variable with corrections above \n", + "\n", + "\n", + "#removing punctuations ----- use the REPLACE FUNCTION. \n", + "\n", + "clean_poem = new_string.replace(\",\", \"\").replace(\"'\",\"\").replace(\".\",\"\")\n", + "\n", + "print(f\"\\n{clean_poem}\")\n", + "\n" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "data-analytics", "language": "python", "name": "python3" }, @@ -126,7 +235,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.23" } }, "nbformat": 4,