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
129 changes: 120 additions & 9 deletions cfu-data-types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,87 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'name': 'asjkl', 'age': '50', 'address': 'sdjkl', 'salary': '6541.23', 'expenses': '3214.56'}\n"
]
}
],
"source": [
"# prompt the user to enter their personal information such as name, age, address, salary, and expenses\n",
"#make dictionary\n",
"keys = [\"name\", \"age\", \"address\", \"salary\", \"expenses\"]\n",
"requested_data = {}\n",
"#ask for input\n",
"for key in keys:\n",
" user_input = input(f\"Please enter your {key}:\")\n",
" requested_data[key] = user_input\n",
"\n",
"print(requested_data)\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Party money after expenses: 3326.7 euro\n",
"3326.6699999999996\n",
"False\n"
]
}
],
"source": [
"#perform some calculations to determine how much money they have left after expenses.\n",
"\n",
"try:\n",
" #convert money into floats\n",
" salary = float(requested_data[\"salary\"])\n",
" expenses = float(requested_data[\"expenses\"])\n",
" age = int(requested_data[\"age\"])\n",
" #calculate rest\n",
" after_expenses = (salary - expenses)\n",
" #round the remaining money to one decimal. \n",
" print(f\"Party money after expenses: {after_expenses:.1f} euro\")\n",
"\n",
"except ValueError:\n",
" print(\"Please make sure that salary and expensens are numbers\")\n",
"\n",
"print(after_expenses)\n",
"#Use a boolean variable to indicate whether the remaining salary is greater than or equal to 500. \n",
"good_salary = 500 > after_expenses\n",
"print(good_salary)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(asjkl, who is 50 years old, and lives in jkhkhuk has 3326.7 euros left from her salary after expenses. It is False that she has more than $500 left.\n"
]
}
],
"source": [
"# Your code here\n"
"name = requested_data[\"name\"]\n",
"addres = requested_data[\"address\"]\n",
"print(f\"({name}, who is {age} years old, and lives in {address} has {after_expenses:.1f} euros left from her salary after expenses. It is {good_salary} that she has more than $500 left.\")"
]
},
{
Expand Down Expand Up @@ -85,7 +161,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 61,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -102,17 +178,52 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 70,
"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",
"pyhton is awesome!\n",
"['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire\\nSome', 'say', 'in', 'ice\\nFrom', 'what', 'I’ve', '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\\npyhton', 'is', 'awesome!']\n"
]
}
],
"source": [
"# Your code here\n"
"# removes the punctuation and leaves everything in lowercase.\n",
"punctuation = \",.´\"\n",
"cleaned_poem = ''.join([char for char in poem if char not in punctuation])\n",
"#Concatenate the resulting string with the string \"python is awesome!\"\n",
"python = \"\"\"pyhton is awesome!\"\"\"\n",
"#store the result in a new variable. \n",
"new_poem = cleaned_poem + \"\\n\" + python\n",
"print(new_poem)\n",
"#Split the string into a list of strings using the space delimiter, save it in a variable `poem_list` and print it. \n",
"poem_list = new_poem.split(\" \")\n",
"print(poem_list)\n"
]
},
{
"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 +237,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down