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
198 changes: 190 additions & 8 deletions cfu-data-types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,54 @@
"- *Use data type conversion functions. Recommended external resources: [Data type conversion](https://www.geeksforgeeks.org/type-conversion-in-python/)*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# prompt the user to enter their personal information such as name, age, address, salary, and expenses, and then perform some calculations to determine how much money they have left after expenses. \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"What is yout name? Rui\n",
"What is your age? 15\n",
"What is your address? Belas\n",
"What is your salary? 500\n",
"What is your expenses? 400\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"I have 100.0 left in the bank\n",
"Rui, who is 15 years old, and lives in Belas has 100.0 dollars more left from her salary after expenses. It is not good that she has more than 100.0 left.\n"
]
}
],
"source": [
"# Your code here\n"
"name = input(\"What is your name?\")\n",
"age = int(input(\"What is your age?\")) \n",
"address = input(\"What is your address?\") \n",
"salary = float(input(\"What is your salary?\")) \n",
"expenses = float(input(\"What are your expenses?\"))\n",
"\n",
"money = salary - expenses \n",
"money = round(money, 1) \n",
"is_salary_good = money >= 500 \n",
"\n",
"print(f\"I have {money} left in the bank\") \n",
"print (f\"{name}, who is {age} years old, and lives in {address} has {money} dollars more left from her salary after expenses. It is {is_salary_good} that she has more than $500 left.\")\n",
"\n",
"\n",
"\n"
]
},
{
Expand Down Expand Up @@ -85,7 +126,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -102,12 +143,153 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {},
"outputs": [],
"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": [
"import string\n",
"def remove_punctuation(poem):\n",
" return poem.translate(str.maketrans(\"\", \"\", string.punctuation))\n",
"\n",
"def to_lowercase(poem):\n",
" return poem.lower()\n",
"\n",
"clean_poem = remove_punctuation(to_lowercase(poem)) \n",
"print(clean_poem) "
]
},
{
"cell_type": "code",
"execution_count": 45,
"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 python is awesome!\n",
"259\n"
]
},
{
"data": {
"text/plain": [
"['some',\n",
" 'say',\n",
" 'the',\n",
" 'world',\n",
" 'will',\n",
" 'end',\n",
" 'in',\n",
" 'fire',\n",
" 'some',\n",
" 'say',\n",
" 'in',\n",
" 'ice',\n",
" 'from',\n",
" 'what',\n",
" 'i’ve',\n",
" 'tasted',\n",
" 'of',\n",
" 'desire',\n",
" 'i',\n",
" 'hold',\n",
" 'with',\n",
" 'those',\n",
" 'who',\n",
" 'favor',\n",
" 'fire',\n",
" 'but',\n",
" 'if',\n",
" 'it',\n",
" 'had',\n",
" 'to',\n",
" 'perish',\n",
" 'twice',\n",
" 'i',\n",
" 'think',\n",
" 'i',\n",
" 'know',\n",
" 'enough',\n",
" 'of',\n",
" 'hate',\n",
" 'to',\n",
" 'say',\n",
" 'that',\n",
" 'for',\n",
" 'destruction',\n",
" 'ice',\n",
" 'is',\n",
" 'also',\n",
" 'great',\n",
" 'and',\n",
" 'would',\n",
" 'suffice',\n",
" 'python',\n",
" 'is',\n",
" 'awesome!']"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"import string\n",
"def remove_punctuation(poem):\n",
" return poem.translate(str.maketrans(\"\", \"\", string.punctuation))\n",
"\n",
"def to_lowercase(poem):\n",
" return poem.lower()\n",
"\n",
"clean_poem = remove_punctuation(to_lowercase(poem)) \n",
"\n",
"python_poem = clean_poem + \" python is awesome!\"\n",
"\n",
"print(python_poem)\n",
"print(len(python_poem))\n",
"poem_list = python_poem.split()\n",
"poem_list"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -126,7 +308,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down