From 30fd01cbf2e5430997e5ad6b6b2631eefaf25a06 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 07:49:16 +0000 Subject: [PATCH 1/3] =?UTF-8?q?a=C3=B1adido=20ejercicio=20021?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/021-square_root/README.es.md | 25 ++++++++++++++ exercises/021-square_root/README.md | 25 ++++++++++++++ exercises/021-square_root/app.py | 1 + exercises/021-square_root/solution.hide.py | 9 +++++ exercises/021-square_root/test.py | 39 ++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 exercises/021-square_root/README.es.md create mode 100644 exercises/021-square_root/README.md create mode 100644 exercises/021-square_root/app.py create mode 100644 exercises/021-square_root/solution.hide.py create mode 100644 exercises/021-square_root/test.py diff --git a/exercises/021-square_root/README.es.md b/exercises/021-square_root/README.es.md new file mode 100644 index 00000000..668ace61 --- /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 +``` + +## 💡 Pista: + ++ 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..28bfa9d2 --- /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 +``` + +## 💡 Hint: + ++ 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 From 6435756dfbf145cf05e90afea8b964296be67fd2 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Tue, 2 Jan 2024 04:28:22 +0100 Subject: [PATCH 2/3] Update README.es.md --- exercises/021-square_root/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/021-square_root/README.es.md b/exercises/021-square_root/README.es.md index 668ace61..4fd0cb58 100644 --- a/exercises/021-square_root/README.es.md +++ b/exercises/021-square_root/README.es.md @@ -18,7 +18,7 @@ square_root(50) 7.07 ``` -## 💡 Pista: +## 💡 Pistas: + Recuerda que el módulo `math` es una herramienta muy útil. From cbbbde428fcc9985cace603e9be64e4080180c2a Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Tue, 2 Jan 2024 04:28:35 +0100 Subject: [PATCH 3/3] Update README.md --- exercises/021-square_root/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/021-square_root/README.md b/exercises/021-square_root/README.md index 28bfa9d2..5dd6907b 100644 --- a/exercises/021-square_root/README.md +++ b/exercises/021-square_root/README.md @@ -18,7 +18,7 @@ square_root(50) 7.07 ``` -## 💡 Hint: +## 💡 Hints: + Remember, the `math` module is a very useful tool.