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
259 changes: 253 additions & 6 deletions cfu-data-types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,92 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"# We def a simple funct that allows uw to input comfy the data we want [age, address, salary and expenses]\n",
"# and then stores it on a dictionary. Then, we return that dict as \"user_info\"\n",
"def input_user_info(user_info):\n",
" name= str(input(\"Enter your name: \"))\n",
" age= int(input(\"Enter your current age: \"))\n",
" address= str(input(\"Enter your current address: \"))\n",
" salary= int(input(\"Enter your anual salary: \"))\n",
" expenses= int(input(\"Enter your mensual expenses: \"))\n",
"\n",
" user_info= {\"name\": name, \"age\": age, \"address\": address, \"salary\": salary, \"expenses\": expenses}\n",
" return user_info"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"# We cast user_input_info\n",
"user_info= input_user_info(user_info)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'name': 'Keb', 'age': 23, 'address': 'Calle Las Palmas', 'salary': 255, 'expenses': 144}\n"
]
}
],
"source": [
"print(user_info)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"# By doing this, we store a bool either the result: if salary is greater or equal to 500 i'll be True, otherwise, False\n",
"salary_treshold= user_info[\"salary\"] >= 500\n",
"print(salary_treshold)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Keb, who is 23 years old, and lives in Calle Las Palmas has 111$ dollars left from his salary after expenses. It is False that he has more than 500$ left\n"
]
}
],
"source": [
"# We want to print: (*name*, who is *age* years old, and lives in *address* has *remaining_salary* \n",
"# dollars left from her salary after expenses. It is *is_salary_good* that she has more than $500 left.)\n",
"remainig_salary= user_info[\"salary\"] - user_info[\"expenses\"]\n",
"\n",
"print(\n",
" f\"{user_info[\"name\"]}, who is {user_info[\"age\"]} years old, and lives in {user_info[\"address\"]} \" +\n",
" f\"has {remainig_salary}$ dollars left from his salary after expenses. It is {salary_treshold} that he has more than 500$ left\"\n",
" )"
]
},
{
Expand Down Expand Up @@ -85,7 +166,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -100,19 +181,185 @@
"And would suffice.\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"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",
"\n",
"Our poem is 245 lenght\n"
]
}
],
"source": [
"print(poem)\n",
"print(f\"\\nOur poem is {len(poem)} lenght\")"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"# We are going to work on _poem to not overwrite the original one.\n",
"parsed_poem= poem"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"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": [
"# Convert to lowercase using .lower()\n",
"parsed_poem= poem.lower()\n",
"print(parsed_poem)"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"# We just take in consideration \",\" and \".\" because we know these are the only\n",
"# sings of punctuation the poem has, but the correct form will be taking every one like \"?\", \"!\", \";\", and so on \n",
"punctuations= [\",\", \".\"]\n",
"\n",
"# Using a for-in, we replace every that is on our punctuations list on our poem and replaces it with an empty space\n",
"for sing in punctuations:\n",
" parsed_poem= parsed_poem.replace(sing, \"\")"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"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": [
"print(parsed_poem)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# We put \"\\n\" in python_is_great for make it readable, but we can just left a blank space and it will be tratet the same furthermore\n",
"python_is_great= \"\\npython is awesome!\"\n",
"\n",
"parsed_poem= parsed_poem + python_is_great"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"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",
"python is awesome!\n",
"\n",
"Our poem is 259 length\n"
]
}
],
"source": [
"print(parsed_poem)\n",
"print(f\"\\nOur poem is {len(parsed_poem)} length\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# .split makes all the job for us, but in any case we want to split bu comma, we need to werite it as a param:\n",
"# => parsed_poem.split(\",\")\n",
"poem_list= parsed_poem.split()"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['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": [
"print(poem_list)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -126,7 +373,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down