Skip to content

Commit 99795bd

Browse files
authored
Merge pull request 4GeeksAcademy#113 from josemoracard/jose4-06-forEach_loop
exercises 06-for-each-loop to 08.1-Merge_list
2 parents 3443334 + 05b450c commit 99795bd

File tree

23 files changed

+165
-108
lines changed

23 files changed

+165
-108
lines changed
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# `06` `ForEach` loop
1+
# `06` Loop and print by condition
22

3-
Es posible recorrer una lista usando un bucle de la función for. Tú tienes que especificar qué hacer en cada iteración del bucle.
3+
Es posible recorrer una lista usando un bucle `for` especificando además qué hacer en cada iteración del bucle.
44

55
## 📝 Instrucciones:
66

7-
Justo ahora, el código está imprimiendo todos los elementos en la lista.
8-
9-
1. Por favor, cambia el código para imprimir solo los números **divisibles entre 14**.
7+
1. Por favor, modifica el código para imprimir solo los números **divisibles entre 14**.
108

119
## 💡 Pista:
1210

13-
+ Un número X es divisible entre 2 si: `(X % 2 === 0)`
11+
+ Un número x es divisible entre 2 si: `(x % 2 == 0)`

exercises/06-forEach_loop/README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
# `06` ForEach loop
1+
# `06` Loop and print by condition
22

3-
It is possible to traverse a list using a `for` loop. You have to specify what to do on each iteration of the loop.
3+
It is possible to traverse a list using a `for` loop, also specifying what to do on each iteration of the loop.
44

5-
## 📝Instructions:
5+
## 📝 Instructions:
66

7-
Right now, the code is printing all the items in the list.
7+
1. Please modify the code to print only the numbers **divisible by 14**.
88

9-
1. Please change the function code to print only
10-
the numbers **divisible by 14**.
9+
## 💡 Hint:
1110

12-
## 💡 Pista:
13-
14-
+ A number x is divisible by 2 if: `(x % 2 === 0)`
11+
+ A number x is divisible by 2 if: `(x % 2 == 0)`

exercises/06-forEach_loop/app.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
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]
22

33

4-
for numb in my_list:
5-
#the magic go here:
6-
7-
print(numb)
8-
4+
for i in my_list:
5+
# The magic happens here
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
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]
2+
3+
4+
for i in my_list:
5+
# The magic happens here
6+
if (i % 14 == 0):
7+
print(i)

exercises/06-forEach_loop/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ 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)")
22-
assert bool(regex.search(content)) == True
22+
assert bool(regex.search(content)) == True
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
# `06.1` Everything is awesome
2-
## Instrucciones:
1+
# `06.1` Everything is Awesome
32

4-
1. Compara el elemento. Si es 1 mete el número en la lista `new_list`.
3+
## 📝 Instrucciones:
54

6-
2. Compara el elemento. Si es `0` mete "Yahoo" en la lista `new_list`, en lugar del número.
5+
1. Compara el elemento. Si es `1`, añade el número en la lista `new_list`.
76

8-
## Resultado esperado:
7+
2. Compara el elemento. Si es `0`, añade `Yahoo` en la lista `new_list`, en lugar del número.
8+
9+
## 💻 Resultado esperado:
910

1011
```py
1112
Ejemplo de salida para [0,0,1,1,0]:
1213

13-
Yahoo,
14-
Yahoo,
14+
'Yahoo',
15+
'Yahoo',
1516
1,
1617
1,
17-
Yahoo
18-
```
18+
'Yahoo'
19+
```
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# `06.1` Everything is Awesome
22

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

5-
1. Compare the item if it is 1 push the number to the list `new_list`.
5+
1. Compare the item; if it is `1`, push the number to the list `new_list`.
66

7-
2. Compare the item if it is 0 push `Yahoo` to the list `new_list` (instead of the number).
7+
2. Compare the item; if it is `0`, push `Yahoo` to the list `new_list` (instead of the number).
88

9-
## Expected Result:
9+
## 💻 Expected Result:
1010

1111
```py
1212
Example output for [0,0,1,1,0]:
1313

14-
Yahoo,
15-
Yahoo,
14+
'Yahoo',
15+
'Yahoo',
1616
1,
1717
1,
18-
Yahoo
19-
```
18+
'Yahoo'
19+
```
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
my_list = [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 1 ]
1+
my_list = [1, 0, 0, 0, 1, 0, 0, 0, 1, 1]
22

33
def my_function(numbers):
44
new_list = []
5-
for numb in numbers:
6-
#The magic go here:
5+
for i in numbers:
6+
# The magic happens here
7+
78

89
return new_list
10+
911
print(my_function(my_list))
10-
11-
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
my_list = [1, 0, 0, 0, 1, 0, 0, 0, 1, 1]
2+
3+
def my_function(numbers):
4+
new_list = []
5+
for i in numbers:
6+
# The magic happens here
7+
if (i == 0):
8+
new_list.append("Yahoo")
9+
elif(i == 1):
10+
new_list.append(1)
11+
12+
return new_list
13+
14+
print(my_function(my_list))

exercises/07-Do_while/README.es.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# `07` Do while
1+
# `07` Do While
22

3-
Hacer, hacer, hacer.
4-
5-
La función `while()` es otro ejemplo de bucle en python es menos común usarla, pero es un bucle:
3+
La función `while()` es otro ejemplo de bucle en Python, es menos común usarla, pero es un bucle:
64

75
```py
86
x = 1
@@ -13,15 +11,15 @@ while x < 6:
1311

1412
## 📝 Instrucciones:
1513

16-
1. Imprime cada número de iteración en la cónsola desde el `20` a `1`, pero **concatena un signo de exclamación** a la salida si el número es un múltiplo de `5`.
14+
1. Imprime cada iteración en la consola de los números del `20` al `1`, pero **concatena un signo de exclamación** si el número es múltiplo de 5.
1715

18-
2. al final imrpime `LIFTOFF`.
16+
2. Al final imprime `LIFTOFF`.
1917

2018
## 💡 Pista:
2119

2220
+ https://www.w3schools.com/python/python_while_loops.asp
2321

24-
## Resultado esperado:
22+
## 💻 Resultado esperado:
2523

2624
```py
2725
Ejemplo de salida en la consola:

0 commit comments

Comments
 (0)