diff --git a/cfu-data-types.ipynb b/cfu-data-types.ipynb index e0fee02..1b28a02 100644 --- a/cfu-data-types.ipynb +++ b/cfu-data-types.ipynb @@ -32,28 +32,91 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "In this exercise, 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", + "En este ejercicio, pida al usuario que ingrese su información personal, como nombre, edad, dirección, salario y gastos, y luego realice algunos cálculos para determinar cuánto dinero le queda después de los gastos. \n", "\n", - "Use data type casting to ensure that the age, salary, and expenses are stored as integers or floats, as appropriate, and round the remaining money to one decimal. \n", + "Utilice la conversión de tipos de datos para garantizar que la edad, el salario y los gastos se almacenen como números enteros o flotantes, según corresponda, y redondee el resto a un decimal. \n", "\n", - "Use a boolean variable to indicate whether the remaining salary is greater than or equal to 500. \n", + "Utilice una variable booleana para indicar si el salario restante es mayor o igual a 500. \n", "\n", - "Finally, you will use string formatting to print a message to the screen in the following format: \n", - "\"*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.\", using the mentioned variables.\n", + "Finalmente, utilizará el formato de cadena para imprimir un mensaje en la pantalla en el siguiente formato: \n", + "\"*nombre*, que tiene *edad* años y vive en *dirección*, le sobran *salario_restante* de su salario después de gastos. Es *salario_bueno* que le sobran más de $500.\", utilizando las variables nombradas.\n", "\n", - "*Hint:* \n", - "- *You can use the input() function to ask the user to enter their information. Beware that input() function returns a String.*\n", - "- *You can round the remaining salary to one decimal using the round() function.*\n", - "- *Use data type conversion functions. Recommended external resources: [Data type conversion](https://www.geeksforgeeks.org/type-conversion-in-python/)*" + "*Pista:* \n", + "- *Puedes usar la función input() para pedirle al usuario que ingrese su información. Tenga en cuenta que la función input() devuelve una cadena.*\n", + "- *Puedes redondear el salario restante a un decimal usando la función round().*\n", + "- *Utilizar funciones de conversión de tipos de datos. Recursos externos recomendados: [Conversión de tipo de datos](https://www.geeksforgeeks.org/type-conversion-in-python/)*" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "crear un diccionario\n", + "colocar las valores a las claves del diccionario\n", + "ese nuevo diccionario preguntar si la resta de salario y gastos son mayor e igual a 500\n", + "si es true print\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "diccionario = {}\n", + "\n", + "diccionario['nombre'] = input('ingresa tu nombre')\n", + "diccionario['edad'] = int(input('ingresa tu edad'))\n", + "diccionario['direccion'] = (input('ingresa tu direccion'))\n", + "diccionario['salario'] = float(input('ingresa tu salario'))\n", + "diccionario['gasto'] = float(input('ingresa tus gasto mensual'))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "600.6" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "salario_restante = round(diccionario.get('salario') - diccionario.get('gasto'), 1)\n", + "salario_restante" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "salario_bueno = salario_restante >= 500" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "juca, que tiene 34 años y vive en madrid, le sobran 600.6 de su salario despues de gastos. Es True que le sobran mas de $500.\n" + ] + } + ], + "source": [ + "print(f\"{diccionario['nombre']}, que tiene {diccionario['edad']} años y vive en {diccionario['direccion']}, le sobran {salario_restante} de su salario despues de gastos. Es {salario_bueno} que le sobran mas de $500.\")" ] }, { @@ -68,24 +131,23 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Write code that takes text from the variable `poem`, removes the punctuation and leaves everything in lowercase. \n", + "Write code that takes text from the `poem` variable, removes punctuation, and leaves everything lowercase. \n", "\n", "Concatenate the resulting string with the string \"python is awesome!\" and store the result in a new variable. \n", "\n", - "Print the length of the new string.\n", + "Prints the length of the new string.\n", "\n", - "Split the string into a list of strings using the space delimiter, save it in a variable `poem_list` and print it. \n", + "Split the string into a list of strings using the space delimiter, store it in a variable `poem_list` and print it.\n", "\n", "*Hint:*\n", - "\n", "- *You can use the len() function to get the length of a string.*\n", - "- *Search string methods to accomplish the other steps. Recommended External Resources: [Python String Methods](https://www.w3schools.com/python/python_ref_string.asp)*\n", - "- *Use method chaining to simplify your code. If you are not sure what it is, read this tutorial before: https://pyneng.readthedocs.io/en/latest/book/04_data_structures/method_chaining.html*\n" + "- *Find string methods to perform the other steps. Recommended external resources: [Python String Methods](https://www.w3schools.com/python/python_ref_string.asp)*\n", + "- *Use method chaining to simplify your code. If you are not sure what it is, read this tutorial first: https://pyneng.readthedocs.io/en/latest/book/04_data_structures/method_chaining.html*" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -102,17 +164,56 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "import string\n", + "poem_low = poem.lower()\n", + "poema_limpio = poem_low.translate(str.maketrans('','', string.punctuation + '’'))" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "258\n" + ] + } + ], + "source": [ + "texto = \"python is awesome!\"\n", + "nuevo_texto = poema_limpio + \" \" + texto\n", + "print(len(nuevo_texto))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['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": [ + "poem_list = nuevo_texto.split()\n", + "print(poem_list)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -126,7 +227,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,