Skip to content

Commit 9acc9d3

Browse files
committed
need to update
2 parents d0f3179 + f240480 commit 9acc9d3

File tree

16 files changed

+127
-154
lines changed

16 files changed

+127
-154
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@
1313
*.pyc
1414
__pycache__/
1515
.pytest_cache/
16+
17+
!/.breathecode
18+
/.breathecode/**
19+
!/.breathecode/resets
20+
!/.breathecode/resets/**

.gitpod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ports:
66
onOpen: open-preview
77
tasks:
88
- command: >
9-
bc run:exercises -e=gitpod;
9+
bc run;
1010
# github:
1111
# prebuilds:
1212
# # enable for the master/default branch (defaults to true)

LICENSE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
2+
3+
By accessing Breathe Code we assume you accept these terms and conditions. Do not continue to use Breathe Code's content, applications or tutorials if you do not agree to take all of the terms and conditions stated on this page.
4+
5+
Unless otherwise stated, Breathe Code and/or its licensors own the intellectual property rights for all material on Breathe Code. All intellectual property rights are reserved. You may access this from Breathe Code for your own personal use subjected to restrictions set in these terms and conditions.
6+
7+
You must not:
8+
9+
* Republish material from Breathe Code
10+
* Sell, rent or sub-license material from Breathe Code
11+
* Reproduce, duplicate or copy material from Breathe Code
12+
* Redistribute content from Breathe Code
13+
14+
You can read the full version of Breathe Code's terms and conditions here: [Terms and Conditions](http://breatheco.de/terms-and-conditions)

exercises/01-hello-world/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# `01` Hello World
22

33
In Python, we use `print` to make the computer write anything we want (the content of a variable, a given string, etc.)
4-
in something called `"the console".`
4+
in something called `the console`.
55

66
Every language has a console, as it was the only way to interact with the users at the beginning
77
(before the Windows or MacOS arrived). Today, printing in the console is used mostly as a
@@ -15,6 +15,7 @@ print("How are you?")
1515
📝 Instructions:
1616

1717
```md
18-
Use the `print()` function to print `"Hello World"` on the console. Feel free to try other things as well.
18+
Use the `print()` function to print `Hello World` on the console.
1919
```
20+
Feel free to try other things as well.
2021

exercises/01-hello-world/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# On the next line, use Python's print function to say `Hello World` in the console (this exercise is case-sensitive!)
1+
# On the next line, use Python's print function to say `Hello World` in the console (this exercise is case-sensitive!)

exercises/01-hello-world/test.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
1-
import io
2-
import sys
3-
import os
4-
sys.stdout = buffer = io.StringIO()
5-
6-
# from app import my_function
1+
import io, sys, os
72
import pytest
8-
import app
9-
10-
# @pytest.mark.it('Your code needs to print hello on the console')
11-
# def test_for_file_output(capsys):
12-
# captured = buffer.getvalue()
13-
# assert captured == "hello\n" #add \n because the console jumps the line on every print
14-
15-
# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console')
16-
# def test_for_function_output(capsys):
17-
# my_function()
18-
# captured = capsys.readouterr()
19-
# assert captured.out == "Hello Inside Function\n"
203

21-
# @pytest.mark.it('Your function needs to return True')
22-
# def test_for_function_return(capsys):
23-
# assert my_function() == True
24-
25-
@pytest.mark.it("Output 'Hello World'")
26-
def test_output():
27-
captured = buffer.getvalue()
28-
assert "Hello World\n" in captured
4+
@pytest.mark.it("Output 'Hello World' case sensitive")
5+
def test_output(capsys, app):
6+
app()
7+
captured = capsys.readouterr()
8+
assert "Hello World\n" == captured.out
299
# convert everything in the buffer to lower case, captured to lower case
3010

31-
3211
@pytest.mark.it("Use print function")
3312
def test_print():
3413
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
my_list = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday']
33

4-
#1. print the item here
4+
# 1. print the item here
55

6-
#2. change 'thursday'a value here to None
6+
# 2. change the position were 'thursday' is to None
77

8-
#3. print the position of step 2
8+
# 3. print that position now here
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import io
2-
import sys
3-
sys.stdout = buffer = io.StringIO()
4-
5-
from app import my_list
6-
import pytest
1+
import io, sys, pytest
72

83
@pytest.mark.it('Your console have to print the 3rd item from the `list`')
9-
def test_output_one():
10-
print(my_list[2])
11-
captured = buffer.getvalue()
12-
assert "tuesday\n" in captured
4+
def test_output_one(capsys, app):
5+
app()
6+
captured = capsys.readouterr()
7+
assert "tuesday\n" in captured.out
138

149
@pytest.mark.it('Your code have to print the position of step 2')
15-
def test_output_two():
16-
print(my_list[2])
17-
captured = buffer.getvalue()
18-
assert "None\n" in captured
10+
def test_output_two(capsys, app):
11+
app()
12+
captured = capsys.readouterr()
13+
assert "None\n" in captured.out
1914

20-
@pytest.mark.it('Set index[4] to None')
15+
@pytest.mark.it('Set the position were thrusday is to None')
2116
def test_position_two():
17+
from app import my_list
2218
assert my_list[4] is None

exercises/01.2-Retrieve-items/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
my_list = [4,5,734,43,45,100,4,56,23,67,23,58,45,3,100,4,56,23]
22

3-
#Print in the console the 1st and 4th element from the list:
3+
# Print in the console the 1st element on the list
4+
5+
# Print in the console the 4th element on the list

exercises/01.2-Retrieve-items/test.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
import io
2-
import sys
3-
sys.stdout = buffer = io.StringIO()
4-
5-
from app import my_list
6-
import pytest
1+
import io, sys, pytest
72

83

94
@pytest.mark.it('You have to print the 1st element of the list')
10-
def test_output_one():
11-
print(my_list[0])
12-
captured = buffer.getvalue()
13-
assert "4\n" in captured
5+
def test_output_one(capsys, app):
6+
app()
7+
captured = capsys.readouterr()
8+
assert "4\n" in captured.out
149

1510
@pytest.mark.it('You have to print the 4th element of the list')
16-
def test_output_fourd():
17-
print(my_list[3])
18-
captured = buffer.getvalue()
19-
assert "43\n" in captured
11+
def test_output_fourd(capsys, app):
12+
app()
13+
captured = capsys.readouterr()
14+
assert "43\n" in captured.out
2015

exercises/01.3-Print-the-last-one/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#You have to import random function
2-
1+
# import the random package here "import random"
2+
import random
33

44
def generate_random_list():
55
aux_list = []
@@ -11,4 +11,4 @@ def generate_random_list():
1111
return aux_list
1212
my_stupid_list = generate_random_list()
1313

14-
#Feel happy to write the code below, good luck:
14+
# Feel happy to write the code below this comment, good luck!:
Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
1-
import io
2-
import sys
3-
import app
4-
import pytest
1+
import io, sys, pytest, os, re
2+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
53

6-
import os
7-
# from app import the_last_one
8-
import app
9-
10-
11-
sys.stdout = buffer = io.StringIO()
12-
13-
# @pytest.mark.it("create and assign the value to the variable the_last_one")
14-
# def test_create_assign():
15-
# assert app.the_last_one is not None
16-
17-
18-
# @pytest.mark.it("print in the console the_last_one")
19-
# def test_output():
20-
# captured = buffer.getvalue()
21-
# assert str(app.the_last_one) in captured
22-
23-
@pytest.mark.it("Import random function")
4+
@pytest.mark.it("Import the random package")
245
def test_import_random():
25-
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
26-
content = f.read()
27-
assert content.find("import random") > 0
6+
with open(path, 'r') as content_file:
7+
content = content_file.read()
8+
regex = re.compile(r"import(\s)+random")
9+
assert bool(regex.search(content)) == True
2810

2911
@pytest.mark.it("Create the variable the_last_one")
30-
def test_create():
31-
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
32-
content = f.read()
33-
assert content.find("the_last_one") > 0
12+
def test_variable_exists(app):
13+
try:
14+
app.the_last_one
15+
except AttributeError:
16+
raise AttributeError("The variable 'the_last_one' should exist on app.py")
3417

3518
@pytest.mark.it("Assign the last number to the variable")
36-
def test_assing():
37-
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
38-
content = f.read()
39-
assert content.find("the_last_one = my_stupid_list[-1]") > 0
19+
def test_assing(app):
20+
assert app.the_last_one == app.my_stupid_list[-1]
21+
22+
@pytest.mark.it("Use the function print")
23+
def test_use_print():
24+
with open(path, 'r') as content_file:
25+
content = content_file.read()
26+
regex = re.compile(r"print(\s)*\(")
27+
assert bool(regex.search(content)) == True
4028

4129
@pytest.mark.it("Print the last element")
42-
def test_output():
43-
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
44-
content = f.read()
45-
assert content.find("print(the_last_one)") > 0
30+
def test_output(capsys, app):
31+
import app
32+
captured = capsys.readouterr()
33+
assert str(app.my_stupid_list[-1])+"\n" in captured.out

exercises/01.4-Add-item-to-list/test.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
import io
2-
import sys
3-
sys.stdout = buffer = io.StringIO()
1+
import io, sys, pytest, os, random
42

5-
import pytest
6-
import app
7-
import os
8-
import random
9-
from app import my_list
10-
11-
# @pytest.mark.it("Add ten random numbers to the list")
12-
# def test_add_numb():
13-
# assert app.my_list.append(random.randint(1, 100)) is not None
14-
15-
# @pytest.mark.it("Output of the list with 15 items numbers")
16-
# def test_output():
17-
# captured = buffer.getvalue()
18-
# assert str(app.my_list) in captured
19-
20-
@pytest.mark.it("Import random function")
3+
@pytest.mark.it("Import the random package")
214
def test_import_random():
22-
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
23-
content = f.read()
24-
assert content.find("import random") > 0
5+
with open(path, 'r') as content_file:
6+
content = content_file.read()
7+
regex = re.compile(r"import(\s)+random")
8+
assert bool(regex.search(content)) == True
259

2610
@pytest.mark.it("Use the for loop")
27-
def test_for():
28-
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
29-
content = f.read()
30-
assert content.find("for x in range(1, 10):") > 0
11+
def test_for_loop():
12+
with open(path, 'r') as content_file:
13+
content = content_file.read()
14+
regex = re.compile(r"for(\s)+(\w)+in(\s)+range")
15+
assert bool(regex.search(content)) == True
3116

3217
@pytest.mark.it("Add the ten random numbers to the list")
3318
def test_add():

exercises/01.5-loop-seventeen/README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
# `01.5` Loop from 1 to 17
22

3-
To loop a specific number of times, we can use range(). In Python, range() returns a sequence of numbers starting with 0, incrementing by 1 each time until it reaches the range.
3+
To loop a specific number of times, we can use `range(<start>,<end>)`.
44

5-
range() function example:
5+
In Python, `range(x,y)` returns a sequence of numbers starting with X, incrementing by 1 each time until it reaches the range.
66

7-
for x in range(5):
7+
For example:
8+
9+
```python
10+
for x in range(0,5):
811
print(x)
9-
10-
expected output:
12+
```
13+
14+
Expected output:
15+
```md
1116
0
1217
1
1318
2
1419
3
1520
4
21+
```
1622

1723
Note that the number specified in range(), 5 in this example, is never reached and 4 is our last output. We can incorporate additional parameters to further specify (now could be a good time to google or at least check the HINT section ;) ).
1824

1925
# 📝Instructions from your teacher:
26+
2027
1. Count from 1 to 17 with a loop and print each number on the console.
2128

2229
💡HINT:

exercises/01.5-loop-seventeen/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#Your code here, have fun:
1+
# Your code here, have fun:

exercises/01.5-loop-seventeen/test.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import io
2-
import sys
3-
sys.stdout = buffer = io.StringIO()
1+
import io, sys, os, pytest, re
2+
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
43

54

6-
import os
7-
import pytest
8-
import app
9-
10-
@pytest.mark.it("Output from 1 to 17")
11-
def test_output():
12-
captured = buffer.getvalue()
13-
assert "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n" in captured
14-
15-
16-
17-
@pytest.mark.it("Make sure that you use for loop!!!")
5+
@pytest.mark.it("Use the for loop")
186
def test_for_loop():
7+
with open(path, 'r') as content_file:
8+
content = content_file.read()
9+
regex = re.compile(r"for(\s)+[a-zA-Z\-_]+(\s)+in(\s)+range.*")
10+
assert bool(regex.search(content)) == True
11+
12+
@pytest.mark.it("Use the function print once inside your loop")
13+
def test_use_print():
14+
with open(path, 'r') as content_file:
15+
content = content_file.read()
16+
regex = re.compile(r"print(\s)*\(")
17+
assert bool(regex.search(content)) == True
1918

20-
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
21-
content = f.read()
22-
assert content.find("for") > 0
19+
@pytest.mark.it("Print on the console from 1 to 17 (do not print 0)")
20+
def test_output(capsys, app):
21+
app()
22+
captured = capsys.readouterr()
23+
assert "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n" in captured.out

0 commit comments

Comments
 (0)