Skip to content

Commit 3443334

Browse files
authored
Merge pull request #112 from josemoracard/jose3-02-Loop-list
exercises 02-loop-list to 05.1-sum_odd_items
2 parents e10e543 + 12b4e8f commit 3443334

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+222
-182
lines changed

exercises/02-Loop-list/README.es.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
# `02` Loop a list
1+
# `02` Loop list
22

33
## 📝 Instrucciones:
44

55
1. Imprimir todos los elementos en la consola, en lugar de solo un elemento de la lista.
66

7-
```py
8-
Tendrás que iterar a lo largo de la lista entera usando un bucle `for`.
9-
```
7+
> Tendrás que iterar a lo largo de la lista entera usando un bucle `for`.
108
119
## 💡 Pista:
1210

1311
+ Si tu objetivo es imprimir cada elemento, que es una tarea repetitiva, podemos usar un bucle. Piensa, por cada item(`each_item`) de `my_list`, ¿Qué queremos? Podemos hacer la referencia a cada item usando `each_item` y ejecutar cualquier operación que queramos en cada iteración.
1412

15-
## Resultado esperado:
13+
## 💻 Resultado esperado:
1614

1715
```py
1816
232

exercises/02-Loop-list/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ tutorial: "https://www.youtube.com/watch?v=VK7jmXad64k"
44

55
# `02` Loop list
66

7-
## 📝Instructions:
7+
## 📝 Instructions:
88

9-
1. Print all of the elements in the console, instead of just the single value of the list.
9+
1. Print all the elements in the console instead of just a single value of the list.
1010

11-
```py
12-
You will have to loop through the whole array using a for loop.
13-
```
14-
## 💡 Hint:
11+
> You will have to loop through the whole array using a `for` loop.
12+
13+
## 💡 Hint:
1514

1615
+ If our goal is to print every item, which is a repetitive task, we can use a loop. Think, for `each_item` in `my_list`, what do we want? We can then use the namespace reference to each item by using `each_item` and perform any operations we want upon each iteration.
1716

18-
## Expected result:
17+
## 💻 Expected result:
1918

2019
```py
2120
232

exercises/02-Loop-list/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
my_list = [232,32,1,4,55,4,3,32,3,24,5,5,5,34,2,35,5365743,52,34,3,55]
22

3-
#Your code go here:
4-
print(my_list[0])
3+
# Your code here
4+
print(my_list[0])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
my_list = [232,32,1,4,55,4,3,32,3,24,5,5,5,34,2,35,5365743,52,34,3,55]
2+
3+
# Your code here
4+
for item in my_list:
5+
print(item)

exercises/02-Loop-list/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io, sys, pytest, os, re
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

4-
@pytest.mark.it("Print the all items from the list")
4+
@pytest.mark.it("Print all items from the list")
55
def test_output(capsys, app):
66
app()
77
captured = capsys.readouterr()

exercises/02.1-Loop-from-the-top/README.es.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
# `02.1` Loop from the top
1+
# `02.1` Loop from the end
22

3-
```py
4-
Este bucle es `iterando` la lista de principio a fin... incrementando uno a uno.
5-
```
3+
Este bucle está iterando la lista de principio a fin, incrementando uno en uno.
64

75
## 📝 Instrucciones:
86

97
1. Vamos a intentar iterar desde el fin hasta el principio.
108

11-
## Resultado esperado:
9+
## 💻 Resultado esperado:
1210

1311
```js
1412
12
@@ -25,4 +23,4 @@ Este bucle es `iterando` la lista de principio a fin... incrementando uno a uno.
2523
4
2624
5
2725
3423
28-
```
26+
```

exercises/02.1-Loop-from-the-top/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
tutorial: "https://www.youtube.com/watch?v=tFCstq-Us3I"
33
---
44

5-
# `02.1` Loop from the top
5+
# `02.1` Loop from the end
66

7-
```py
8-
This loop is `looping` the list from beginning to end... increasing one by one.
9-
```
7+
This loop is *looping* the list from beginning to end, increasing one by one.
108

11-
## 📝Instructions::
9+
## 📝 Instructions:
1210

13-
1. Lets try looping from the end to the beginning.
11+
1. Let's try looping from the end to the beginning.
1412

15-
## Expected result:
13+
## 💻 Expected result:
1614

1715
```py
1816
12
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
my_sample_list = [3423,5,4,47889,654,8,867543,23,48,56432,55,23,25,12]
22

3-
# The magic pass below:
4-
# Create a variable, like "i", that uses the last index position in the array "my_sample_list". Remember we can access the length property of an array using len, and that the position will always be 1 less than the item number (item one is index 0, item 5653 would be one less...)
3+
# Modify the loop below to print from end to start
54

6-
# You can now use the variable holding the last position to iterate until you get to the first position- which will always be 0. Create a for loop using that variable, make sure the value of the variable is modified on each iteration of the loop.
7-
# while some_variable_reference > 0:
8-
# print(my_sample_list[some_variable_reference])
9-
# chage after doing what we wanted, change the variables value so that the next pass it references the new index position
5+
for i in range(0, len(my_sample_list)):
6+
print(my_sample_list[i])
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
my_sample_list = [3423,5,4,47889,654,8,867543,23,48,56432,55,23,25,12]
2+
3+
# Modify the loop below to print from end to start
4+
5+
for i in range(len(my_sample_list) - 1, -1, -1):
6+
print(my_sample_list[i])

exercises/02.1-Loop-from-the-top/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ def test_output(capsys, app):
77
captured = capsys.readouterr()
88
assert "12\n25\n23\n55\n56432\n48\n23\n867543\n8\n654\n47889\n4\n5\n3423\n" in captured.out
99

10-
@pytest.mark.it("Use the while loop")
10+
@pytest.mark.it("Use the for loop")
1111
def test_for_loop():
1212
with open(path, 'r') as content_file:
1313
content = content_file.read()
14-
regex = re.compile(r"while(\s)+[a-zA-Z\-_]+(\s)")
14+
regex = re.compile(r"for(\s)+[a-zA-Z\-_]+(\s)")
1515
assert bool(regex.search(content)) == True

0 commit comments

Comments
 (0)