Skip to content
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

09.1 for loop min value #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion exercises/09.1-For_loop_min_value/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ Es posible recorrer una lista usando un bucle `for` para listas, tú tienes que

## 📝 Instrucciones:

1. Por favor, usa la función for para obtener el menor valor de la lista e imprimirlo en la consola.
1. Crea una función llamada `minInteger`

2. Dentro de la función mencionada, por favor utilice el bucle `for` para obtener el valor mínimo de la lista.

3. La función `minInteger` debe devolver el valor mínimo.

4. Por último, debe imprimir el valor devuelto fuera de la función.

+ `print(minInteger(my_list))`

## 💡 Pista:

Expand Down
9 changes: 8 additions & 1 deletion exercises/09.1-For_loop_min_value/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ It is possible to traverse a list using the `for` loop, you have to specify what

## 📝Instructions:

1. Please use the `for` loop function to get the minimum value of the list and print it in the console.
1.Create a function called `minInteger`

2.Inside the aforementioned function, please use the `for` loop function to get the minimum value of the list.

3.The `minInteger` function should then return the minimum value.

4.Lastly, you should print the returned value outside the function.
+ `print(minInteger(my_list))`

## 💡 Hint:

Expand Down
19 changes: 14 additions & 5 deletions exercises/09.1-For_loop_min_value/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
big_number = 999999999999999
my_list = [3344,34334,454543,342534,4563456,3445,23455,234,262,2335,
43323,4356,345,4545,452,345,434,36,345,4334,5454,345,4352,23,365,345,47,63,
425,6578759,768,834,754,35,32,445,453456,56,7536867,3884526,4234,35353245,53244523,
566785,7547,743,4324,523472634,26665,63432,54645,32,453625,7568,5669576,754,64356,542644,
35,243,371,3251,351223,13231243,734,856,56,53,234342,56,545343]

for number in my_list:
if number < big_number:
big_number = number
#Your code here:
def minInteger(my_list):
min = my_list[0]

for n in my_list:
if n <= min:
min = n

return min

print(big_number)
print(minInteger(my_list))
33 changes: 29 additions & 4 deletions exercises/09.1-For_loop_min_value/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import io, sys, os, pytest, re
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'

@pytest.mark.it("Print the minimum value from the list")
def test_min(capsys, app):
app()
@pytest.mark.it('The function minInteger must exist')
def test_function_existence(capsys, app):
assert app.minInteger

@pytest.mark.it("The function should return the minimum number from a list")
def test_output(capsys, app):
result = app.minInteger([43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34])
assert result == 1

@pytest.mark.it("The function should print the minimum number from my_list")
def test_printed_output(capsys, app):
def minInteger_wrapper(my_list):
result = app.minInteger(my_list)
print(result)
return result

original_minInteger = app.minInteger
app.minInteger = minInteger_wrapper

exec(open(app.__file__).read())
captured = capsys.readouterr()
assert "23\n" in captured.out

app.minInteger = original_minInteger

assert int(captured.out.strip()) == min(app.my_list)

@pytest.mark.it("The function should work with other lists")
def test_output_2(capsys, app):
result = app.minInteger([43,23,6,8733,43,1,4,6,3,67,8,99999,3,7,5435,63])
assert result == 1

@pytest.mark.it("Use the for loop")
def test_for_loop():
Expand Down