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
184 changes: 176 additions & 8 deletions cfu-data-types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,99 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# 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\"))"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'int'>\n",
"<class 'float'>\n",
"<class 'float'>\n"
]
}
],
"source": [
"#Data type\n",
"print(type(age))\n",
"print(type(salary))\n",
"print(type(expenses))"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1108.5"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"remaining_salary = salary - expenses\n",
"remaining_salary = round(remaining_salary, 1)\n",
"remaining_salary"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"is_salary_good = remaining_salary >= 500\n",
"is_salary_good"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Maya, who is 27 years old, and lives in Madrid has 1108.5 dollars left from her salary after expenses. It is True that she has more than $500 left.\n"
]
}
],
"source": [
"print(f\"{name}, who is {age} years old, and lives in {address} has {remaining_salary} dollars left from her salary after expenses. \\\n",
" It is {is_salary_good} that she has more than $500 left.\")"
]
},
{
Expand Down Expand Up @@ -85,7 +173,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -102,17 +190,97 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'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 suffice'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import re\n",
"#removes the punctuation and leaves everything in lowercase\n",
"clean_poem = re.sub(r\"[^a-zA-Z0-9\\s]\",\"\" \"\", poem).lower()\n",
"clean_poem"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'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 suffice python is awesome!'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Concatenate the resulting with the string \"python is awesome!\"\n",
"result_clean = clean_poem + \" \" +\"python is awesome!\"\n",
"result_clean"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"258\n"
]
}
],
"source": [
"# Your code here\n"
"#Len of the result_clean\n",
"print(len(result_clean))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"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', 'suffice', 'python', 'is', 'awesome!']\n"
]
}
],
"source": [
"#split the result_clean using the space delimitator \n",
"poem_list = result_clean.split(\" \")\n",
"print(poem_list)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -126,7 +294,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.10.2"
}
},
"nbformat": 4,
Expand Down