Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bbde7f6

Browse files
Merge pull request #60 from josemoracard/jose9-add-exercise-21-average
añadido ejercicio 021
2 parents 746e6af + cbbbde4 commit bbde7f6

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

‎exercises/021-square_root/README.es.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `021` square root
2+
3+
## 📝 Instrucciones:
4+
5+
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.
6+
7+
2. Si el número resultante tiene decimales, solo conserva los 2 primeros.
8+
9+
## 📎 Ejemplo de entrada:
10+
11+
```py
12+
square_root(50)
13+
```
14+
15+
## 📎 Ejemplo de salida:
16+
17+
```py
18+
7.07
19+
```
20+
21+
## 💡 Pistas:
22+
23+
+ Recuerda que el módulo `math` es una herramienta muy útil.
24+
25+
+ Para conservar el número deseado de decimales en un número dado, puedes utilizar el método `round()`.

‎exercises/021-square_root/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `021` square root
2+
3+
## 📝 Instructions:
4+
5+
1. Create a function named `square_root()`, which receives a number as a parameter and returns the square root of the given number.
6+
7+
2. If the resulting number has decimals, please only keep the first 2.
8+
9+
## 📎 Example input:
10+
11+
```py
12+
square_root(50)
13+
```
14+
15+
## 📎 Example output:
16+
17+
```py
18+
7.07
19+
```
20+
21+
## 💡 Hints:
22+
23+
+ Remember, the `math` module is a very useful tool.
24+
25+
+ To keep the desired number of decimals in a given number, you can use the `round()` method.

‎exercises/021-square_root/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Your code here
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Your code here
2+
import math
3+
4+
def square_root(number):
5+
result = round(math.sqrt(number), 2)
6+
return result
7+
8+
9+
print(square_root(50))

‎exercises/021-square_root/test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import io, sys, os, re, pytest
2+
import app
3+
4+
@pytest.mark.it('You should create a function named square_root')
5+
def test_square_root_exists(app):
6+
try:
7+
from app import square_root
8+
assert square_root
9+
except AttributeError:
10+
raise AttributeError("The function 'square_root' should exist on app.py")
11+
12+
@pytest.mark.it('The function must return something')
13+
def test_function_return(capsys, app):
14+
assert app.square_root(25) != None
15+
16+
@pytest.mark.it('The function must return a float number')
17+
def test_function_return_type(capsys, app):
18+
assert type(app.square_root(25)) == type(1.0)
19+
20+
@pytest.mark.it('Testing the function square_root with the number 50, it should return 7.07')
21+
def test_square_root_50(app):
22+
try:
23+
assert app.square_root(50) == 7.07
24+
except AttributeError:
25+
raise AttributeError("The function 'square_root' should return the value 7.07")
26+
27+
@pytest.mark.it('Testing the function square_root with the number 2.25, it should return 1.5')
28+
def test_square_root_2_25(app):
29+
try:
30+
assert app.square_root(2.25) == 1.5
31+
except AttributeError:
32+
raise AttributeError("The function 'square_root' should return the value 1.5")
33+
34+
@pytest.mark.it('Testing the function square_root with the number 0, it should return 0')
35+
def test_square_root_0(app):
36+
try:
37+
assert app.square_root(0) == 0
38+
except AttributeError:
39+
raise AttributeError("The function 'square_root' should return the value 0")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /