diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..d4f30c9 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -49,11 +49,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Danna, who is 32 years old, and lives in Seattle, CA has 8010.0 dollars left from her salary after expenses. It is True that she has more than $500 left.\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Step 1: Gather input\n", + "name = input(\"Enter your name: \")\n", + "age = int(input(\"Enter your age: \")) # Convert to integer\n", + "address = input(\"Enter your address: \")\n", + "salary = float(input(\"Enter your salary: \")) # Convert to float\n", + "expenses = float(input(\"Enter your expenses: \")) # Convert to float\n", + "\n", + "# Step 2: Perform calculations\n", + "remaining_salary = round(salary - expenses, 1) # Subtract and round to one decimal\n", + "\n", + "# Step 3: Boolean variable\n", + "is_salary_good = remaining_salary >= 500\n", + "\n", + "# Step 4: Create the formatted message\n", + "message = f\"{name}, who is {age} years old, and lives in {address} has {remaining_salary} dollars left from her salary after expenses. It is {is_salary_good} that she has more than $500 left.\"\n", + "\n", + "# Step 5: Print the message\n", + "print(message)" ] }, { @@ -102,17 +127,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "258\n", + "['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'ive', '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": [ - "# Your code here\n" + "import re\n", + "\n", + "# Original poem\n", + "poem = \"\"\"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", + "# Clean up and transform the poem\n", + "poem_clean = re.sub(r'[^\\w\\s]', '', poem).lower()\n", + "\n", + "# Concatenate with string \"python is awesome!\"\n", + "combined_string = poem_clean + \" python is awesome!\"\n", + "\n", + "# Print the length of the combined string\n", + "length_of_string = len(combined_string)\n", + "print(length_of_string)\n", + "\n", + "# Split into a list and print it\n", + "poem_list = combined_string.split()\n", + "print(poem_list)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -126,7 +185,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,