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 65abfe8

Browse files
Merge pull request #114 from josemoracard/jose5-08.2-Divide_and_conquer
exercises 08.2-divide-and-conquer to 09-Max-integer-from-my_list
2 parents 99795bd + 2cd4d3a commit 65abfe8

File tree

10 files changed

+96
-68
lines changed

10 files changed

+96
-68
lines changed

‎exercises/08.2-Divide_and_conquer/README.es.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@
22

33
## 📝 Instrucciones:
44

5-
1. Crea una función llamada `merge_two_list` que espere una lista números enteros.
5+
1. Crea una función llamada `sort_odd_even` que espere una lista de números enteros.
66

7-
2. Itera la lista y separa los números pares e impares en diferentes listas.
7+
2. Itera la lista y separa los números *pares* e *impares*.
88

9-
3. Si el número es impar colócalo en una lista llamada `odd`.
9+
3. Crea una lista vacía llamada `sorted_list` y empieza a insertar los números *impares*.
1010

11-
4. Si el número es par colócalo en una lista llamada `even`.
11+
4. Si el número es par, colócalo en una lista llamada `even`.
1212

13-
5. Luego concatena la lista `odd` y la lista `even` para combinarlas. Recuerda que la lista `odd` va primero y que debes añadirle la lista `even`.
13+
5. Luego concatena la lista `even` en `sorted_list`. Recuerda que los números *impares* van primero y luego debes añadirle la lista `even` después.
1414

1515
## 💡 Pista:
1616

1717
+ Crea variables vacías cuando necesites almacenar información.
1818

19-
## Resultado esperado:
19+
+ Lee sobre el método `extend()`: https://www.w3schools.com/python/ref_list_extend.asp
20+
21+
## 💻 Resultado esperado:
22+
23+
Debe quedar todo dentro de una sola lista, no debe haber listas anidadas.
2024

2125
```py
22-
mergeTwoList([1,2,33,10,20,4])
26+
sort_odd_even([1,2, 33,10,20,4])
2327

24-
[[1,33,2], [10,20,4]]
28+
[1, 33, 2, 10, 20, 4] # <-- Si
29+
[[1,33], [2,10,20,4]] # <-- No
2530
```
2631

32+
33+
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
# `08.2` Divide and conquer:
1+
# `08.2` Divide and conquer
22

3-
## 📝Instructions:
3+
## 📝Instructions:
44

5-
1. Create a function called `merge_two_list` that expects an list of numbers (integers).
5+
1. Create a function called `sort_odd_even` that expects a list of numbers (integers).
66

7-
2. Loop through the list and separate the `odd` and the `even` numbers in different lists.
7+
2. Loop through the list and separate the *odd* and the *even* numbers.
88

9-
3. If the number is odd number push it to a placeholder list named `odd`.
9+
3. Create a variable called `sorted_list`to start appending the *odd* numbers.
1010

11-
4. If the number is even number push it to a placeholder list named `even`.
11+
4. If the number is even, push it to a placeholder list named `even`.
1212

13-
5. Then concatenate the `odd` list to the even list to combine them. Remember, the `odd` list comes first and you have to append the even`mergeTwoList`.
13+
5. Then insert the `even` list into the `sorted_list`. Remember, the *odd* numbers come first, and you have to insert the `even` list after.
1414

15-
## 💡 Hint:
15+
## 💡 Hints:
1616

1717
+ Create empty (placeholder) variables when you need to store data.
1818

19-
## Expected result:
19+
+ Check out the `extend()` method: https://www.w3schools.com/python/ref_list_extend.asp
20+
21+
## 💻 Expected result:
22+
23+
Everything should be inside a single list; there should not be nested lists.
2024

2125
```py
22-
mergeTwoList([1,2,33,10,20,4])
26+
sort_odd_even([1,2, 33,10,20,4])
2327

24-
[[1,33,2], [10,20,4]]
28+
[1, 33, 2, 10, 20, 4] # <-- Yes
29+
[[1,33], [2,10,20,4]] # <-- No
2530
```
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
list_of_numbers = [4,80,85,59,37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68]
1+
list_of_numbers = [4,80,85,59,37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68]
22

3+
# Your code here
34

4-
#Your code here:
55

6-
7-
print(merge_two_list(list_of_numbers))
6+
print(sort_odd_even(list_of_numbers))
87

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
list_of_numbers = [4, 80, 85, 59, 37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68]
2+
3+
# Your code here
4+
def sort_odd_even(numbers):
5+
sorted_list = []
6+
even = []
7+
8+
for i in numbers:
9+
if (i % 2 == 1):
10+
sorted_list.append(i)
11+
elif (i % 2 == 0):
12+
even.append(i)
13+
14+
sorted_list.extend(even)
15+
return sorted_list
16+
17+
print(sort_odd_even(list_of_numbers))
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import io, sys, os, pytest, re
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

4-
@pytest.mark.it("Concatenate both lists. Remember the Odd list come first")
4+
@pytest.mark.it("Concatenate both lists. Remember the odd list comes first")
55
def test_odd_even(capsys, app):
66
import app
77
captured = capsys.readouterr()
8-
assert "[[85, 59, 37, 25, 5, 81, 41, 55], [4, 80, 64, 66, 20, 64, 22, 76, 76, 96, 2, 68]]\n" in captured.out
8+
assert "[85, 59, 37, 25, 5, 81, 41, 55, 4, 80, 64, 66, 20, 64, 22, 76, 76, 96, 2, 68]\n" in captured.out
99

1010
@pytest.mark.it("Use the for loop")
1111
def test_for_loop():
@@ -14,16 +14,16 @@ def test_for_loop():
1414
regex = re.compile(r"for(\s)")
1515
assert bool(regex.search(content)) == True
1616

17-
@pytest.mark.it("Use if statement")
17+
@pytest.mark.it("Use an if statement")
1818
def test_if():
1919
with open(path, 'r') as content_file:
2020
content = content_file.read()
2121
regex = re.compile(r"if(\s)")
2222
assert bool(regex.search(content)) == True
2323

24-
@pytest.mark.it('1. You should create a function named merge_two_list')
24+
@pytest.mark.it('You should create a function named sort_odd_even')
2525
def test_variable_exists(app):
2626
try:
27-
app.merge_two_list
27+
app.sort_odd_even
2828
except AttributeError:
29-
raise AttributeError("The function 'merge_two_list' should exist on app.py")
29+
raise AttributeError("The function 'sort_odd_even' should exist on app.py")

‎exercises/09-Max_integer_from_list/README.es.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@
22

33
## 📝 Instrucciones:
44

5-
1. Crea una función llamada `maxInteger`.
5+
1. Crea una función llamada `max_integer`.
66

77
2. Esta función debe tomar una lista como parámetro de entrada y devolver el número máximo encontrado en la lista.
88

9-
3. Deberías usar un bucle 'for' para recorrer la lista.
9+
3. Deberías usar un bucle `for` para recorrer la lista.
1010

1111
4. Utiliza la función `print()` para imprimir lo que devuelve la función al ser llamada.
1212

13-
-Por **ejemplo**: `print(myFunction(param))`
13+
+Por ejemplo: `print(my_function(param))`
1414

15+
## 💡 Pistas:
1516

16-
## 💡 Pista:
17-
18-
- Defina una variable auxiliar y establece su valor en 0.
17+
- Defina una variable auxiliar y establece su valor como el primer elemento de la lista.
1918

2019
- Compara la variable con todos los elementos de la lista.
2120

2221
- Reemplaza el valor de la variable cada vez que el valor de la lista sea mayor que el valor de la variable auxiliar.
2322

2423
- Al final, tendrás el número más grande almacenado en la variable.
2524

26-
## Resultado esperado:
25+
## 💻 Resultado esperado:
2726

28-
```py
29-
Tu resultado debería ser 5435.
30-
```
27+
```py
28+
5435
29+
```

‎exercises/09-Max_integer_from_list/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
## 📝 Instructions:
44

5-
1. Create a function named `maxInteger`
5+
1. Create a function named `max_integer`
66

7-
2. This function should take a list as an input parameter and
8-
return the maximum number found in the list.
7+
2. This function should take a list as an input parameter and return the maximum number found in the list.
98

10-
3. You should use a 'for' loop to iterate through the list.
9+
3. You should use a `for` loop to iterate through the list.
1110

1211
4. Use the `print()` function to print what the function returns when it is called.
13-
- For **example**: `print(myFunction(param))`
12+
13+
+ For example: `print(my_function(param))`
1414

15-
## 💡 Hint:
15+
## 💡 Hints:
1616

17-
- Define an auxiliar variable and set the first value to `0`.
17+
- Define an auxiliary variable and set the first value to the first element on the list.
1818

19-
- Then compare the variables with all the items in the list.
19+
- Then compare the variable with all the items in the list.
2020

21-
- Replace the value every time the new element is bigger than the one stored in the auxiliar variable.
21+
- Replace the value every time the new element is bigger than the one stored in the auxiliary variable.
2222

23-
- At the end you will have the biggest number stored in the variable.
23+
- At the end, you will have the biggest number stored in the variable.
2424

25-
##Expected Result:
25+
##💻 Expected result:
2626

27-
```py
28-
Your result should be 5435.
27+
```py
28+
5435
2929
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
my_list = [43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34]
22

3-
#Your code go from here:
3+
#Your code here
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
my_list = [43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34]
22

3-
#Your code go from here:
4-
def maxInteger(arr):
5-
maxInt=0
6-
for i in range(len(arr)):
7-
if arr[i] > maxInt:
8-
maxInt = arr[i]
9-
return maxInt
3+
# Your code here
4+
def max_integer(list):
5+
max_int = list[0]
6+
7+
for i in range(len(list)):
8+
if list[i] > max_int:
9+
max_int = list[i]
10+
return max_int
1011

11-
print(maxInteger(my_list))
12+
print(max_integer(my_list))
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import io, sys, os, pytest, re
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

4-
@pytest.mark.it('The function maxInteger must exist')
4+
@pytest.mark.it('The function max_integer must exist')
55
def test_function_existence(capsys, app):
6-
assert app.maxInteger
6+
assert app.max_integer
77

8-
@pytest.mark.it("The function should return the maximun number from a list")
8+
@pytest.mark.it("The function should return the maximum number from a list")
99
def test_output(capsys, app):
10-
result = app.maxInteger([43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34])
10+
result = app.max_integer([43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34])
1111
assert result == 5435
1212

1313
@pytest.mark.it("The function should work with other lists")
1414
def test_output_2(capsys, app):
15-
result = app.maxInteger([43,23,6,8733,43,1,4,6,3,67,8,99999,3,7,5435,63])
15+
result = app.max_integer([43,23,6,8733,43,1,4,6,3,67,8,99999,3,7,5435,63])
1616
assert result == 99999
1717

1818
@pytest.mark.it("Use the for loop")
@@ -22,9 +22,9 @@ def test_for_loop():
2222
regex = re.compile(r"for(\s)*")
2323
assert bool(regex.search(content)) == True
2424

25-
@pytest.mark.it("Use if statement")
25+
@pytest.mark.it("Use an if statement")
2626
def test_if():
2727
with open(path, 'r') as content_file:
2828
content = content_file.read()
2929
regex = re.compile(r"if(\s)*")
30-
assert bool(regex.search(content)) == True
30+
assert bool(regex.search(content)) == True

0 commit comments

Comments
(0)

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