Skip to content

añadido ejercicio 021 #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions exercises/021-square_root/README.es.md
Original file line number Diff line number Diff line change
@@ -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()`.
25 changes: 25 additions & 0 deletions exercises/021-square_root/README.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions exercises/021-square_root/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Your code here
9 changes: 9 additions & 0 deletions exercises/021-square_root/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
39 changes: 39 additions & 0 deletions exercises/021-square_root/test.py
Original file line number Diff line number Diff line change
@@ -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")