diff --git a/exercises/021-square_root/README.es.md b/exercises/021-square_root/README.es.md new file mode 100644 index 00000000..4fd0cb58 --- /dev/null +++ b/exercises/021-square_root/README.es.md @@ -0,0 +1,25 @@ +# `021` square root + +## 📝 Instrucciones: + +1. Crea una función llamada `square_root()`, que reciba un número como parámetro y devuelva la raíz cuadrada del número dado. + +2. Si el número resultante tiene decimales, solo conserva los 2 primeros. + +## 📎 Ejemplo de entrada: + +```py +square_root(50) +``` + +## 📎 Ejemplo de salida: + +```py +7.07 +``` + +## 💡 Pistas: + ++ Recuerda que el módulo `math` es una herramienta muy útil. + ++ Para conservar el número deseado de decimales en un número dado, puedes utilizar el método `round()`. diff --git a/exercises/021-square_root/README.md b/exercises/021-square_root/README.md new file mode 100644 index 00000000..5dd6907b --- /dev/null +++ b/exercises/021-square_root/README.md @@ -0,0 +1,25 @@ +# `021` square root + +## 📝 Instructions: + +1. Create a function named `square_root()`, which receives a number as a parameter and returns the square root of the given number. + +2. If the resulting number has decimals, please only keep the first 2. + +## 📎 Example input: + +```py +square_root(50) +``` + +## 📎 Example output: + +```py +7.07 +``` + +## 💡 Hints: + ++ Remember, the `math` module is a very useful tool. + ++ To keep the desired number of decimals in a given number, you can use the `round()` method. diff --git a/exercises/021-square_root/app.py b/exercises/021-square_root/app.py new file mode 100644 index 00000000..fce62c1d --- /dev/null +++ b/exercises/021-square_root/app.py @@ -0,0 +1 @@ +# Your code here diff --git a/exercises/021-square_root/solution.hide.py b/exercises/021-square_root/solution.hide.py new file mode 100644 index 00000000..909e1b1b --- /dev/null +++ b/exercises/021-square_root/solution.hide.py @@ -0,0 +1,9 @@ +# Your code here +import math + +def square_root(number): + result = round(math.sqrt(number), 2) + return result + + +print(square_root(50)) \ No newline at end of file diff --git a/exercises/021-square_root/test.py b/exercises/021-square_root/test.py new file mode 100644 index 00000000..e96a8011 --- /dev/null +++ b/exercises/021-square_root/test.py @@ -0,0 +1,39 @@ +import io, sys, os, re, pytest +import app + +@pytest.mark.it('You should create a function named square_root') +def test_square_root_exists(app): + try: + from app import square_root + assert square_root + except AttributeError: + raise AttributeError("The function 'square_root' should exist on app.py") + +@pytest.mark.it('The function must return something') +def test_function_return(capsys, app): + assert app.square_root(25) != None + +@pytest.mark.it('The function must return a float number') +def test_function_return_type(capsys, app): + assert type(app.square_root(25)) == type(1.0) + +@pytest.mark.it('Testing the function square_root with the number 50, it should return 7.07') +def test_square_root_50(app): + try: + assert app.square_root(50) == 7.07 + except AttributeError: + raise AttributeError("The function 'square_root' should return the value 7.07") + +@pytest.mark.it('Testing the function square_root with the number 2.25, it should return 1.5') +def test_square_root_2_25(app): + try: + assert app.square_root(2.25) == 1.5 + except AttributeError: + raise AttributeError("The function 'square_root' should return the value 1.5") + +@pytest.mark.it('Testing the function square_root with the number 0, it should return 0') +def test_square_root_0(app): + try: + assert app.square_root(0) == 0 + except AttributeError: + raise AttributeError("The function 'square_root' should return the value 0") \ No newline at end of file