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

23 files changed

+165
-108
lines changed
+4-6
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

+6-9
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

+3-5
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+
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

+2-2
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
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+
```
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+
```
+5-5
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-
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

+5-7
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:

exercises/07-Do_while/README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# `07` D0 While
1+
# `07` Do While
22

3-
DO DO DO
4-
The `while()` function is another loop example in python is less commonly used but it is a loop.
3+
DO DO DO. The `while()` function is another loop example in Python and is less commonly used, but it is still a loop.
54

65
```py
76
x = 1
@@ -12,15 +11,15 @@ while x < 6:
1211

1312
## 📝 Instructions:
1413

15-
1. Print every iteration number on the console from `20` to `1`, but **concatenate an exclamation point** to the output if the number is a multiple of `5`.
14+
1. Print every iteration number on the console from `20` to `1`, but **concatenate an exclamation mark** to the output if the number is a multiple of 5.
1615

17-
2. At the end print() `LIFTOFF`.
16+
2. At the end print `LIFTOFF`.
1817

1918
## 💡 Hint:
2019

2120
+ https://www.w3schools.com/python/python_while_loops.asp
2221

23-
## Expected result:
22+
## 💻 Expected result:
2423

2524
```py
2625
Example Output on the console:

exercises/07-Do_while/app.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
#Your code go here:
1+
# Your code here
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Your code here
2+
3+
number = 20
4+
5+
while number >= 1:
6+
if number % 5 == 0:
7+
print(str(number) + "!")
8+
else:
9+
print(number)
10+
number -= 1
11+
12+
print("LIFTOFF")

exercises/07-Do_while/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_for_loop():
1616
regex = re.compile(r"while(\s)\S*")
1717
assert bool(regex.search(content)) == True
1818

19-
@pytest.mark.it("Use if statement")
19+
@pytest.mark.it("Use an if statement")
2020
def test_if():
2121
with open(path, 'r') as content_file:
2222
content = content_file.read()
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# `08` Delete element
22

3-
La unica forma de borrar a `Daniella` de la lista (sin trampas)
4-
será crear una nueva lista con todas las demás personas, excepto Daniella.
3+
La única forma de borrar a `Daniella` de la lista (sin trampas) sería crear una nueva lista con todas las demás personas, excepto `Daniella`.
54

65
## 📝 Instrucciones:
76

8-
1. Por favor, crea una función `deletePerson` que elimina a una persona dada de una lista y devuelve una nueva lista sin esa persona.
7+
1. Por favor, crea una función `delete_person` que elimine a una persona dada de una lista y devuelva una nueva lista sin esa persona.
98

10-
## Resultado esperado:
9+
## 💻 Resultado esperado:
1110

1211
```py
13-
Resultado:
14-
['juan', 'ana', 'michelle', 'stefany', 'lucy', 'barak']
12+
Resultado:
13+
14+
['juan', 'ana', 'michelle', 'stefany', 'lucy', 'barak']
1515
['ana', 'michelle', 'daniella', 'stefany', 'lucy', 'barak']
1616
['juan', 'ana', 'michelle', 'daniella', 'stefany', 'lucy', 'barak']
17-
```
17+
```

exercises/08-Delete_element/README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# `08` Delete element
22

3-
The only way to delete `Daniella` from the list (without cheating) will be to create a new list with all the other people but `Daniella`.
3+
The only way to delete `Daniella` from the list (without cheating) would be to create a new list with all the other people but `Daniella`.
44

55
## 📝 Instructions:
66

7-
1. Please create a `deletePerson` function that deletes any given person from the list and returns a new list without that person.
7+
1. Please create a `delete_person` function that deletes any given person from the list and returns a new list without that person.
88

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

1111
```py
12-
Result:
13-
['juan', 'ana', 'michelle', 'stefany', 'lucy', 'barak']
12+
Result:
13+
14+
['juan', 'ana', 'michelle', 'stefany', 'lucy', 'barak']
1415
['ana', 'michelle', 'daniella', 'stefany', 'lucy', 'barak']
1516
['juan', 'ana', 'michelle', 'daniella', 'stefany', 'lucy', 'barak']
16-
```
17+
```

exercises/08-Delete_element/app.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
people = ['juan','ana','michelle','daniella','stefany','lucy','barak']
22

3-
#Your code go here:
4-
def deletePerson(person_name):
5-
#Your code go here:
3+
def delete_person(person_name):
4+
# Your code here
65

7-
print(deletePerson("daniella"))
8-
print(deletePerson("juan"))
9-
print(deletePerson("emilio"))
6+
7+
8+
# Don't delete anything below
9+
print(delete_person("daniella"))
10+
print(delete_person("juan"))
11+
print(delete_person("emilio"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
people = ['juan','ana','michelle','daniella','stefany','lucy','barak']
2+
3+
def delete_person(person_name):
4+
# Your code here
5+
updated_people = list(people)
6+
7+
if person_name in updated_people:
8+
updated_people.remove(person_name)
9+
10+
return updated_people
11+
12+
# Don't delete anything below
13+
print(delete_person("daniella"))
14+
print(delete_person("juan"))
15+
print(delete_person("emilio"))

exercises/08-Delete_element/test.py

+2-2
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
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
# `08.1` Merge list
2-
3-
Dado que vivimos en un nuevo mundo, no deberían haber colores ni etiquetas ¿verdad?
1+
# `08.1` Merge List
42

53
## 📝 Instrucciones:
64

7-
Escribe una función que una dos listas y devuelva una nueva lista (`merge_list`) uniendo todos los valores de las dos listas.
5+
Escribe una función `merge_list` que una dos listas y devuelva una nueva lista uniendo todos los valores de las dos listas.
86

97
1. Declara una lista vacía.
108

119
2. Itera las dos listas.
1210

13-
3. Concatena los valores a la lista nueva (`merge_list`).
11+
3. Inserta los valores a la lista nueva.
12+
13+
4. Imprime la nueva variable con las dos listas.
14+
15+
## 💡 Pistas:
1416

15-
4. Imprime la variable con las dos listas.
17+
+ Tendrás que iterar cada lista e insertar sus elementos en una nueva lista.
1618

17-
## 💡 Pista:
19+
+ Hay más formas para combinar listas en Python. Este es un buen momento para buscar en Internet "cómo combinar listas en python".
1820

19-
- Tendrás que iterar cada lista e insertar sus elementos en una nueva lista.
20-
## Resultado esperado:
21+
## 💻 Resultado esperado:
2122

2223
```py
23-
Salida esperada:
24-
['Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell', 'Lucas', 'Jake', 'Scott', 'Amy', 'Molly', 'Hannah', 'Lucas']
24+
['Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell', 'Lucas', 'Jake', 'Scott', 'Amy', 'Molly', 'Hannah', 'Lucas']
2525
```
2626

2727

0 commit comments

Comments
 (0)