diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..f32ee1f 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -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" ] }, { @@ -85,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -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": { @@ -126,7 +308,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,