diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..5b9733d 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,11 +49,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Jeremy, who is 29 years old, and lives in Paris, \n", + "has a remaining salary of 831.0 after expenses.\n", + "You have a good amount of savings.\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "# First we create an empty dictionary to store the user personal information when he/she inputs it.\n", + "user_info = {}\n", + "\n", + "# We then prompt the user to input their personal information and store it in the dictionary.\n", + "user_info['name'] = input(\"Enter your name: \")\n", + "user_info['age'] = int(input(\"Enter your age: \"))\n", + "user_info['address'] = input(\"Enter your address: \")\n", + "user_info['salary'] = float(input(\"Enter your salary: \"))\n", + "user_info['expenses'] = float(input(\"Enter your expenses: \"))\n", + "\n", + "# Then we calculate the user's savings by subtracting expenses from salary.\n", + "user_info['savings'] = user_info['salary'] - user_info['expenses']\n", + "\n", + "# We print out the user's personal information and their calculated savings.\n", + "print(f\"\"\"{user_info['name']}, who is {user_info['age']} years old, and lives in {user_info['address']}, \n", + "has a remaining salary of {user_info['savings']} after expenses.\"\"\")\n", + "\n", + "# Finally, we check if the user remaining salary is greater than or equal to 500 using a boolean expression.\n", + "is_salary_good = user_info['savings'] >= 500\n", + "if is_salary_good:\n", + " print(\"You have a good amount of savings.\")\n", + "else:\n", + " print(\"You might want to review your expenses.\")" ] }, { @@ -85,7 +119,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -102,17 +136,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "259\n", + "['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", + "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": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "# First we remove the punctuation from the poem\n", + "poem_clean = poem.replace(\",\", \"\").replace(\".\", \"\").replace(\"’\", \" \")\n", + "\n", + "# Then we convert the poem to lowercase to ensure uniformity\n", + "poem_clean = poem_clean.lower()\n", + "\n", + "# We create a new string to concatenate the clean poem with another sentence\n", + "python_string = \"python is awesome!\"\n", + "new_poem = poem_clean + \" \" + python_string\n", + "\n", + "# We print the length of the new poem\n", + "print(len(new_poem))\n", + "\n", + "# We split the poem into individual words and we store them in a list\n", + "poem_list = new_poem.split()\n", + "print(poem_list)\n", + "print(poem_clean)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -126,7 +196,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.6" } }, "nbformat": 4,