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
86 changes: 79 additions & 7 deletions cfu-data-types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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": {
Expand All @@ -126,7 +198,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down