Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 88 additions & 7 deletions cfu-data-types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,43 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sergio, who is 33 years old, and lives in kut has 0.0 dollars left from her salary after expenses. It is False that she has more than $500 left.\n"
]
}
],
"source": [
"# Your code here\n"
"\"\"\" This code prompts the user to enter their personal information such as name, age, salary and expense and then performs some calculations\n",
" to determine how much money they have left after expenses.\n",
"\n",
" A boolean variable is then used to determine if the remaining salary is greater than or equal to 500\n",
"\"\"\"\n",
"name = input(\"Enter your name: \") # Added space for clarity in prompt\n",
"address = input(\"Enter your address: \")\n",
"age = int(input(\"Enter your age: \"))\n",
"salary = float(input(\"Enter your Salary: \"))\n",
"expenses = float(input(\"Enter your expenses: \"))\n",
"\n",
"# This line of code calculates the remaining money\n",
"remaining_salary = salary - expenses\n",
"\n",
"# Round the remaining salary to one decimal place as required by the prompt\n",
"remaining_salary = round(remaining_salary, 1)\n",
"\n",
"# This next line of code checks if the remaining salary is equal or greater than 500\n",
"# using the comparison operator >=\n",
"is_salary_good = remaining_salary >= 500 # Renamed for clarity as per previous suggestions\n",
"\n",
"# Convert the boolean to a string \"True\" or \"False\" as required for the output message\n",
"is_salary_good_str = \"True\" if is_salary_good else \"False\"\n",
"\n",
"# Print the message in the *exact* specified format regardless of the salary amount\n",
"print(f\"{name}, who is {age} years old, and lives in {address} has {remaining_salary} Euros left from her salary after expenses. It is {is_salary_good_str} that she has more than $500 left.\")\n",
"\n"
]
},
{
Expand Down Expand Up @@ -102,17 +136,64 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Length of the new string: 347\n",
"\n",
"Poem as a list of words:\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"
"# Your code here\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",
"# 1. Remove punctuation and convert to lowercase\n",
"# We create a translation table where every punctuation character is mapped to None,\n",
"# which effectively removes it from the string.\n",
"# Then, we convert the entire string to lowercase using .lower().\n",
"# This uses method chaining: translate() returns a string, on which .lower() is then called.\n",
"translator = str.maketrans('', '', string.punctuation)\n",
"cleaned_poem = poem.translate(translator).lower()\n",
"\n",
"# 2. Concatenate the resulting string with \"python is awesome!\"\n",
"# We add a space before \"python\" to ensure proper word separation.\n",
"result_string = cleaned_poem + \" python is awesome!\"\n",
"\n",
"# 3. Print the length of the new string\n",
"print(f\"Length of the new string: {len(result_string)}\")\n",
"\n",
"# 4. Split the string into a list of strings using the space delimiter\n",
"# The .split() method without arguments splits the string by any whitespace\n",
"# and handles multiple spaces correctly (treating them as a single delimiter).\n",
"poem_list = result_string.split()\n",
"\n",
"# 5. Print the poem_list\n",
"print(\"\\nPoem as a list of words:\")\n",
"print(poem_list)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -126,7 +207,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down