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
167 changes: 158 additions & 9 deletions cfu-data-types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,45 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter your name: Paul Omogiate Obamwonyi\n",
"Enter your age: 33\n",
"Enter your address: 2, Markstrasse\n",
"Enter your Salary: 3330333\n",
"Enter your expenses: 333333\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Paul Omogiate Obamwonyi,who is 33 years old, and lives in 2, Markstrasse has 2997000.0 dollars left from her salary after expenses. It is True that she has more than $500 left.\n"
]
}
],
"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",
"remaining_salary = round(salary - expenses, 1) \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 after expenses. It is {is_salary_good} that she has more than $500 left.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
" \n",
"### Exercise 2: Text Cleaning and Concatenation"
]
},
Expand Down Expand Up @@ -102,19 +129,141 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\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",
"clean_poem = poem.replace(\",\", \"\"). replace(\"’\", \"\").replace(\".\", \"\").lower()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"some say the world will end in fire\n",
"some say in ice\n",
"from what ive 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": [
"print(clean_poem)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"updated_poem = clean_poem + \"python is awesome\""
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"some say the world will end in fire\n",
"some say in ice\n",
"from what ive 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 sufficepython is awesome\n"
]
}
],
"source": [
"print(updated_poem)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"260\n"
]
}
],
"source": [
"print(len(updated_poem))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"poem_list = updated_poem.split(\" \")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire\\nsome', 'say', 'in', 'ice\\nfrom', 'what', 'ive', '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', 'sufficepython', 'is', 'awesome']\n"
]
}
],
"source": [
"print(poem_list)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "pj1_env",
"language": "python",
"name": "python3"
"name": "venv"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -126,7 +275,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.13"
}
},
"nbformat": 4,
Expand Down