diff --git a/exercises/00-Welcome/README.md b/exercises/00-Welcome/README.md new file mode 100644 index 00000000..ea331a2d --- /dev/null +++ b/exercises/00-Welcome/README.md @@ -0,0 +1,24 @@ +# Welcome to Python Beginner Course!! + +We are very excited to have you here !! 🎉 😂 + +During this course you will be learning the following concepts: + +1. How to create and call functions. +2. How to create and call variables. +3. How to concatenate strings. +4. How to use loops and if statements. +5. How to combine and use all these concepts. + + + +## Contributors + +Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): + +1. [Alejandro Sanchez (alesanchezr)](https://github.com/alesanchezr), contribution: (coder) :computer: (idea) 🤔, (build-tests) :warning:, (pull-request-review) :eyes: (build-tutorial) :white_check_mark: (documentation) :book: +1. [Paolo Lucano (plucodev)](https://github.com/plucodev), contribution: (coder), (build-tests) :warning: + +This project follows the +[all-contributors](https://github.com/kentcdodds/all-contributors) +specification. Contributions of any kind are welcome! \ No newline at end of file diff --git a/exercises/01-Console/README.md b/exercises/01-Console/README.md new file mode 100644 index 00000000..5c6b3398 --- /dev/null +++ b/exercises/01-Console/README.md @@ -0,0 +1,16 @@ +# `01` Console + +In Python, we use **print** to make the computer write anything we want (the content of a variable, a given string, etc.) in something called "the console". + +Every language has a console, as it was the only way to interact with the users at the beginning (before the Windows or MacOS arrived). +Today, printing in the console is used mostly as a monitoring tool, ideal to leave a trace of the content of variables during the program execution. + +This is an example of how to use it: +```py +print("How are you?") +``` + +## 📝 Instructions: + +1. Use **print** to print "Hello World" on the console. Feel free to try other things as well. + diff --git a/exercises/01-Console/app.py b/exercises/01-Console/app.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/exercises/01-Console/app.py @@ -0,0 +1 @@ + diff --git a/exercises/01-Console/test.py b/exercises/01-Console/test.py new file mode 100644 index 00000000..d2f519b9 --- /dev/null +++ b/exercises/01-Console/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() +import app +import re +import os +import pytest + +@pytest.mark.it('1. Your code needs to print Hello World! on the console') +def test_for_file_output(capsys): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "print" in s] + my_printIndex = content.index(my_print[0]) + # print(my_print_index) + regex = r"print\(\"Hello World!\"\)" + assert re.match(regex, content[my_printIndex]) + captured = buffer.getvalue() + assert captured == "Hello World!\n" #add \n because the console jumps the line on every print + diff --git a/exercises/01-welcome/README.md b/exercises/01-welcome/README.md deleted file mode 100644 index 803a35e3..00000000 --- a/exercises/01-welcome/README.md +++ /dev/null @@ -1 +0,0 @@ -# Welcome to Python! \ No newline at end of file diff --git a/exercises/02-Declare-Variables/README.md b/exercises/02-Declare-Variables/README.md new file mode 100644 index 00000000..4a4948ed --- /dev/null +++ b/exercises/02-Declare-Variables/README.md @@ -0,0 +1,15 @@ +# `02` Declare Variables + +Variables act as a box (container) that lets you store different types of data. This is how we set a variable: +```py +name = "Daniel" +``` + +## 📝 Instructions: + +1. Declare a new variable with the string value "Yellow" and print the value to the console. + + +## 💡 Hint: + +The name of the variable can be whatever you want, but the value inside has to be the string "Yellow". diff --git a/exercises/02-Declare-Variables/app.py b/exercises/02-Declare-Variables/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/02-Declare-Variables/test.py b/exercises/02-Declare-Variables/test.py new file mode 100644 index 00000000..607dd8b4 --- /dev/null +++ b/exercises/02-Declare-Variables/test.py @@ -0,0 +1,37 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() +import app +# from app import my_function +import pytest +import os +import re + +# @pytest.mark.it('1. Declare a variable with a string value "Yellow" ') +# def test_for_regex(capsys): +# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') +# content = f.readlines() +# content = [x.strip() for x in content] + +# # variable = 'name = "Yellow"' +# variable = r"\w(\s*)=(\s*)\"Yellow\"" +# assert re.match(variable, content[0]) + +@pytest.mark.it('1. Your code needs to print Yellow on the console') +def test_for_file_output(capsys): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_var = [s for s in content if "print" in s] + my_varIndex = content.index(my_var[0]) + # print(my_print_index) + regex_var = r"print(\s*)\(\w*\)" + assert re.match(regex_var, content[my_varIndex]) + my_print = [s for s in content if "Yellow" in s] + my_printIndex = content.index(my_print[0]) + # print(my_print_index) + regex = r"\w*(\s*)=(\s*)\"Yellow\"" + assert re.match(regex, content[my_printIndex]) + captured = buffer.getvalue() + assert captured == "Yellow\n" #add \n because the console jumps the line on every print + diff --git a/exercises/03-Print-Variables-In-The-Console/README.md b/exercises/03-Print-Variables-In-The-Console/README.md new file mode 100644 index 00000000..fafe9401 --- /dev/null +++ b/exercises/03-Print-Variables-In-The-Console/README.md @@ -0,0 +1,13 @@ +# `03` Print the Variables in the console + +You can also use the **print** function to print variables in the console, it's a great way to know their content, like this: +```py +my_super_variable = 'hello' +print(my_super_variable) +``` + +## 📝 Instructions: + +1. Declare a new variable called **color** and assign the value "red" to it. +2. Then, print its value on the console. + diff --git a/exercises/03-Print-Variables-In-The-Console/app.py b/exercises/03-Print-Variables-In-The-Console/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/03-Print-Variables-In-The-Console/test.py b/exercises/03-Print-Variables-In-The-Console/test.py new file mode 100644 index 00000000..6134039c --- /dev/null +++ b/exercises/03-Print-Variables-In-The-Console/test.py @@ -0,0 +1,41 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import app +import os +import re + +@pytest.mark.it("1. You should create a variable named color") +def test_use_forLoop(): + + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + + # regex = r"color = \"red\"" + regex = r"color(\s*)=(\s*)\"red\"" + assert re.match(regex, content[0]) +@pytest.mark.it('2. You should print on the console the value red ') +def test_for_file_output(capsys): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "print" in s] + my_printIndex = content.index(my_print[0]) + # print(my_print_index) + regex = r"print(\s*)\(color\)" + assert re.match(regex, content[my_printIndex]) + captured = buffer.getvalue() + assert captured == "red\n" #add \n because the console jumps the line on every print +# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') +# def test_for_function_output(capsys): +# my_function() +# captured = capsys.readouterr() +# assert captured.out == "Hello Inside Function\n" + +# @pytest.mark.it('Your function needs to return True') +# def test_for_function_return(capsys): +# assert my_function() == True \ No newline at end of file diff --git a/exercises/04-Multiply-Two-Values/README.md b/exercises/04-Multiply-Two-Values/README.md new file mode 100644 index 00000000..7e954c59 --- /dev/null +++ b/exercises/04-Multiply-Two-Values/README.md @@ -0,0 +1,18 @@ +# `04` Multiply Two Values + +Any programming language lets you do basic Math operations like multiplication, division, etc. + +To multiply 2 values in python, you have to use the asterisk operator like this: +```py +resulting_value = 2 * 3 +``` +In this case, we stored the result value of the multiplication into a variable called **resulting_value**. + +## 📝 Instructions: + +1. Please store the result of multiplying 2345 times 7323 in a variable called **variables_are_cool** +2. Now print the result in the console. + + + + diff --git a/exercises/04-Multiply-Two-Values/app.py b/exercises/04-Multiply-Two-Values/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/04-Multiply-Two-Values/test.py b/exercises/04-Multiply-Two-Values/test.py new file mode 100644 index 00000000..5b9ca806 --- /dev/null +++ b/exercises/04-Multiply-Two-Values/test.py @@ -0,0 +1,36 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import os +import app +import re + +@pytest.mark.it('1. You should create a variable named variables_are_cool') +def test_use_variable_name(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + regex = r"variables_are_cool(\s*)=(\s*)2345(\s*)\*(\s*)7323" + # regex = r"color = \"red\"" + # regex = r"color(\s*)=(\s*)\"red\"" + assert re.match(regex, content[0]) + +@pytest.mark.it('2. You should print on the console the variables_are_cool value ') +def test_for_file_output(capsys): + regex = r"print(\s*)\(variables_are_cool\)" + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + # indices = [i for i, s in enumerate(content) if 'print' in s] + # print(int(indices)) + my_print = [s for s in content if "print" in s] + my_print_index = content.index(my_print[0]) + print(my_print_index) + # print([s for s in content if "print" in s]) + my_result = 2345 *7323 + captured = buffer.getvalue() + assert captured == str(my_result)+'\n' + assert re.match(regex, content[my_print_index]) diff --git a/exercises/05-User-Inputed-Values/README.md b/exercises/05-User-Inputed-Values/README.md new file mode 100644 index 00000000..5fc6cba4 --- /dev/null +++ b/exercises/05-User-Inputed-Values/README.md @@ -0,0 +1,13 @@ +# `05` User Inputed Values + +The other cool thing about variables is that you don't need to know their value to be able to work with them. + +For example, the application right now is prompting the user for its age, and then printing it on the console. + +## 📝 Instructions: + +1. Please add 10 years to the value of the age variable. + +- The content of the variable its being previously filled with whatever the user inputs. + + diff --git a/exercises/05-User-Inputed-Values/app.py b/exercises/05-User-Inputed-Values/app.py new file mode 100644 index 00000000..42b66228 --- /dev/null +++ b/exercises/05-User-Inputed-Values/app.py @@ -0,0 +1,4 @@ +age = int(input('What is your age?\n')) +# CHANGE THE CODE BELOW TO ADD 10 TO AGE + +print("Your age is: "+str(age)) diff --git a/exercises/05-User-Inputed-Values/test.py b/exercises/05-User-Inputed-Values/test.py new file mode 100644 index 00000000..74e1cb34 --- /dev/null +++ b/exercises/05-User-Inputed-Values/test.py @@ -0,0 +1,14 @@ +import pytest,os,re,io,sys, mock, json + +@pytest.mark.it("1. You should print on the console the input value + 10") +def test_t(stdin): + _input = json.loads(stdin) + print("####", _input[0]) + my_testString = int(_input[0]) + 10 + print("$$$$$:",int(my_testString) + 10) + with mock.patch('builtins.input', lambda x: _input.pop()): + # f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + sys.stdout = buffer = io.StringIO() + import app + captured = buffer.getvalue() + assert captured == "Your age is: " + str(my_testString)+'\n' diff --git a/exercises/06-String-Concatenation/README.md b/exercises/06-String-Concatenation/README.md new file mode 100644 index 00000000..a730711f --- /dev/null +++ b/exercises/06-String-Concatenation/README.md @@ -0,0 +1,20 @@ +# `06` String Concatenation + +One common task you’ll need to accomplish with any language involves merging or combining strings. +This process is referred to as concatenation. +The best way to describe it is when you take two separate strings – stored by the interpreter – and +merge them so that they become one. + +```py +one = 'a' +two = 'b' +print(one+two); #this will print 'ab' on the console. +``` + + +## 📝 Instructions: + +1. Set the values for my_var1 and my_var2 so the code prints 'Hello World' in the console. + + + diff --git a/exercises/06-String-Concatenation/app.py b/exercises/06-String-Concatenation/app.py new file mode 100644 index 00000000..237c9d46 --- /dev/null +++ b/exercises/06-String-Concatenation/app.py @@ -0,0 +1,6 @@ +# Set the values here + + +## Don't change below this line +the_new_string = my_var1+' '+my_var2 +print(the_new_string) \ No newline at end of file diff --git a/exercises/06-String-Concatenation/test.py b/exercises/06-String-Concatenation/test.py new file mode 100644 index 00000000..4d7e6534 --- /dev/null +++ b/exercises/06-String-Concatenation/test.py @@ -0,0 +1,48 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import app +import os +import re + + +@pytest.mark.it("1. You should create a variable named my_var1") +def test_use_my_var1(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_var1 = [s for s in content if "my_var1" in s] + my_var1Var = content.index(my_var1[0]) + regex_my_var1 = r"my_var1(\s*)=(\s*)\"(\s*)Hello(\s*)\"" + # regex = r"color = \"red\"" + # regex = r"color(\s*)=(\s*)\"red\"" + assert re.match(regex_my_var1, content[my_var1Var]) +@pytest.mark.it("2. You should create a variable named my_var2") +def test_use_my_var2(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_var2 = [s for s in content if "my_var2" in s] + my_var2Var = content.index(my_var2[0]) + regex_my_var2 = r"my_var2(\s*)=(\s*)\"(\s*)World(\s*)\"" + # regex = r"color = \"red\"" + # regex = r"color(\s*)=(\s*)\"red\"" + assert re.match(regex_my_var2, content[my_var2Var]) +@pytest.mark.it('3. Your code needs to print Hello World on the console') +def test_for_file_output(capsys): + + captured = buffer.getvalue() + assert captured == "Hello World\n" #add \n because the console jumps the line on every print + +# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') +# def test_for_function_output(capsys): +# my_function() +# captured = capsys.readouterr() +# assert captured.out == "Hello Inside Function\n" + +# @pytest.mark.it('Your function needs to return True') +# def test_for_function_return(capsys): +# assert my_function() == True \ No newline at end of file diff --git a/exercises/07-Create-a-Basic-HTML/README.md b/exercises/07-Create-a-Basic-HTML/README.md new file mode 100644 index 00000000..9601f021 --- /dev/null +++ b/exercises/07-Create-a-Basic-HTML/README.md @@ -0,0 +1,23 @@ +# `07` Create a basic HTML + +Let's continue using string concatenation to generate HTML... + + + + +## 📝 Instructions: + +1. The code on the left contains 8 variables with different string values, please use +the variables and concatenate them together to set the value of the variable **html_document** +a new string that has the content of a typical HTML document (with the HTML tags in the +right order). + +2. Then, print the value of **html_document** on the console. + +The output should look like this: + +```sh + + +``` + diff --git a/exercises/07-Create-a-Basic-HTML/app.py b/exercises/07-Create-a-Basic-HTML/app.py new file mode 100644 index 00000000..805349de --- /dev/null +++ b/exercises/07-Create-a-Basic-HTML/app.py @@ -0,0 +1,11 @@ +a = '' +b = '' +c = '' +d = '' +e = '' +f = '' +g = '' +h = '<body>' + +# DON'T CHANGE THE CODE ABOVE + diff --git a/exercises/07-Create-a-Basic-HTML/test.py b/exercises/07-Create-a-Basic-HTML/test.py new file mode 100644 index 00000000..c8451a39 --- /dev/null +++ b/exercises/07-Create-a-Basic-HTML/test.py @@ -0,0 +1,35 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import app +import os +import re + + +@pytest.mark.it('1. Your code needs to print a basic html layout on the console') +def test_for_file_output(capsys): + regex = r"print(\s*)\(html_document\)" + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + # indices = [i for i, s in enumerate(content) if 'print' in s] + # print(int(indices)) + my_print = [s for s in content if "print" in s] + my_print_index = content.index(my_print[0]) + captured = buffer.getvalue() + assert re.match(regex, content[my_print_index]) + assert captured == "<html><head><title>\n" #add \n because the console jumps the line on every print +@pytest.mark.it("2. You should create a variable named html_document") +def test_use_my_var1(): + + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "html_document =" in s] + my_htmlDocumentIndex = content.index(my_print[0]) + # print(my_print_index) + regex = r"html_document(\s*)=(\s*)e(\s*)\+(\s*)c(\s*)\+(\s*)g(\s*)\+(\s*)a(\s*)\+(\s*)f(\s*)\+(\s*)h(\s*)\+(\s*)d(\s*)\+(\s*) b" + assert re.match(regex, content[my_htmlDocumentIndex]) diff --git a/exercises/08-Calling-Your-First-Function/README.md b/exercises/08-Calling-Your-First-Function/README.md new file mode 100644 index 00000000..b4d9990a --- /dev/null +++ b/exercises/08-Calling-Your-First-Function/README.md @@ -0,0 +1,17 @@ +# `08` Calling Your First Function + +Functions are amazing because of many things, but mainly because you can encapsulate your code +in pieces and re-use those pieces several times without having to type all that code again. + +IMPORTANT: there's a Replit Classroom dedicated to Functions, we encourage you to go and finish +those after this first Function exercise. (And then, come back). + + + + +## 📝 Instructions: + +1. The function **is_odd** is defined at the beginning of the code, please call that function passing +it the number 45345 and print the result on the console. + + diff --git a/exercises/08-Calling-Your-First-Function/app.py b/exercises/08-Calling-Your-First-Function/app.py new file mode 100644 index 00000000..371555bc --- /dev/null +++ b/exercises/08-Calling-Your-First-Function/app.py @@ -0,0 +1,5 @@ +def is_odd(my_number): + return (my_number % 2 != 0) + + +# your code here diff --git a/exercises/08-Calling-Your-First-Function/test.py b/exercises/08-Calling-Your-First-Function/test.py new file mode 100644 index 00000000..09f6cc21 --- /dev/null +++ b/exercises/08-Calling-Your-First-Function/test.py @@ -0,0 +1,27 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import app +import os +import re +# @pytest.mark.it('Your code needs to print hello on the console') +# def test_for_file_output(capsys): +# captured = buffer.getvalue() +# assert captured == "hello\n" #add \n because the console jumps the line on every print +@pytest.mark.it("1. You should call is_odd function in your print statement and pass the value 45345") +def test_conditional(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "print" in s] + my_printVar = content.index(my_print[0]) + regex = r"print\(is_odd\(45345\)\)" + assert re.match(regex, content[my_printVar]) + +@pytest.mark.it('2. The console should return True ') +def test_for_file_output(capsys): + captured = buffer.getvalue() + assert captured == "True\n" diff --git a/exercises/09-Creating-Your-First-Function/README.md b/exercises/09-Creating-Your-First-Function/README.md new file mode 100644 index 00000000..8e925b33 --- /dev/null +++ b/exercises/09-Creating-Your-First-Function/README.md @@ -0,0 +1,22 @@ +# `09` Creating Your First Function + + +## 📝 Instructions: + +1. The function **add_numbers** is supposed to return the sum of 2 given numbers, please +complete the needed code inside of the function to make it behave as expected. + +The exercise should print the number 7 in the console. + +## 💡 Hint: + +There is a function **"add_numbers"** already declared, it is receiving 2 parameters +(the variables **a** and **b**), as a developer you were given a task to fill the +function content with the code needed to sum variable **a** with variable **b** and +return the result of that operation. + +## Note: +For practicing more with functions, there is a specific Repl.it class about functions +created by 4Geeks Academy that has more than 20 incremental exercises. + + diff --git a/exercises/09-Creating-Your-First-Function/app.py b/exercises/09-Creating-Your-First-Function/app.py new file mode 100644 index 00000000..f4adaf0f --- /dev/null +++ b/exercises/09-Creating-Your-First-Function/app.py @@ -0,0 +1,6 @@ +def add_numbers(a,b): +# YOUR CODE HERE + + + +print(add_numbers(3,4)) \ No newline at end of file diff --git a/exercises/09-Creating-Your-First-Function/test.py b/exercises/09-Creating-Your-First-Function/test.py new file mode 100644 index 00000000..90013d15 --- /dev/null +++ b/exercises/09-Creating-Your-First-Function/test.py @@ -0,0 +1,28 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import app +import os +import re + + +@pytest.mark.it("1. You should add the return statement inside the existing function") +def test_use_my_var1(): + + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_return = [s for s in content if "return" in s] + my_returnIndex = content.index(my_return[0]) + # print(my_print_index) + regex = r"return a(\s*)\+(\s*)b" + assert re.match(regex, content[my_returnIndex]) + +# assert re.match(regex, content) +@pytest.mark.it('2. The console should return 7') +def test_add_variables(capsys): + captured = buffer.getvalue() + assert captured == str(7)+"\n" diff --git a/exercises/10-Create-A-New-Function/README.md b/exercises/10-Create-A-New-Function/README.md new file mode 100644 index 00000000..06c55d76 --- /dev/null +++ b/exercises/10-Create-A-New-Function/README.md @@ -0,0 +1,41 @@ +# `10` Create a New Function + +As you know, functions are a useful block of code that you can re-use as many times +as you need or want. In the last exercise, you had a function that received two parameters (two inputs) and returned the sum of those. Like this: + +```py +def add_numbers(a, b): + print(a + b) + + +``` + +But Python comes with a bunch of "pre defined" functions that you can use, for example: + +```py +import random +# Generates a random number between +# a given positive range +r1 = random.randint(0, 10) +print("Random number between 0 and 10 is % s" % (r1)) + + +``` + +You can use the randint function to get a random decimal number. +randint() is an inbuilt function of the random module in Python3. +The random module gives access to various useful functions and one +of them being able to generate random numbers, which is randint(). + +## 📝 Instructions: + +1. Please now create a function called **generate_random** that generates and print a random number +between 0 and 9 every time it is called. + +## 💡 Hint: + +- One possible solution involves using two predefined functions: the **randint** or **randrange** function. +- Don't forget to import random. +- Check the documentation: https://docs.python.org/3/library/random.html#functions-for-integers + + diff --git a/exercises/10-Create-A-New-Function/app.py b/exercises/10-Create-A-New-Function/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/10-Create-A-New-Function/test.py b/exercises/10-Create-A-New-Function/test.py new file mode 100644 index 00000000..32359127 --- /dev/null +++ b/exercises/10-Create-A-New-Function/test.py @@ -0,0 +1,63 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import os +import app +import re + +@pytest.mark.it('1. You should create a function called generate_random ') +def test_for_function(capsys): + regex = r"def generate_random\(\):" + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + # indices = [i for i, s in enumerate(content) if 'print' in s] + # print(int(indices)) + my_func = [s for s in content if "def generate" in s] + my_func_index = content.index(my_func[0]) + print(my_func_index) + # print([s for s in content if "print" in s]) + assert re.match(regex, content[my_func_index]) + +@pytest.mark.it("2. The function should generate and print a random number between 0 and 9") +def test_print(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "print" in s] + my_printVar = content.index(my_print[0]) + regex = r"print\(random\.rand\w+\(\d+\D*\d+\)\)" + assert re.match(regex, content[my_printVar]) +@pytest.mark.it('3. You should call your function in the correct way ') +def test_for_file_output(capsys): + regex = r"generate_random\(\)" + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + # indices = [i for i, s in enumerate(content) if 'print' in s] + # print(int(indices)) + my_func = [s for s in content if "generate_random()" in s] + my_func_index = content.index(my_func[0]) + print(my_func_index) + # print([s for s in content if "print" in s]) + assert re.match(regex, content[(len(content)-1)]) + +# @pytest.mark.it('Your code needs to print hello on the console') +# def test_generate_random(capsys): +# x = get_generate_random() +# print("x", x) +# captured = buffer.getvalue() +# assert captured == "hello\n" #add \n because the console jumps the line on every print + +# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') +# def test_for_function_output(capsys): +# my_function() +# captured = capsys.readouterr() +# assert captured.out == "Hello Inside Function\n" + +# @pytest.mark.it('Your function needs to return True') +# def test_for_function_return(capsys): +# assert my_function() == True \ No newline at end of file diff --git a/exercises/11-Your-First-If/README.md b/exercises/11-Your-First-If/README.md new file mode 100644 index 00000000..f1e3109a --- /dev/null +++ b/exercises/11-Your-First-If/README.md @@ -0,0 +1,17 @@ +# `11` Your First if... + +The current application is prompting asking how much money the user has. Once the user inputs +the amount, we need to **print** one of the following answers: + + + +## 📝 Instructions: + +1. If the user has more than $100, we answer: "Give me your money!" +2. If the user has more than $50, we answer: "Buy me some coffee you cheap!" +3. If the user has less or equal than $50, we answer: "You are a poor guy, go away!" + +## 💡 Hint: + +- Use an If/else statement to check the value of the "total" variable. +- https://docs.python.org/3/tutorial/controlflow.html#if-statements diff --git a/exercises/11-Your-First-If/app.py b/exercises/11-Your-First-If/app.py new file mode 100644 index 00000000..68b95adf --- /dev/null +++ b/exercises/11-Your-First-If/app.py @@ -0,0 +1,4 @@ + +total = int(input('How much money do you have in your pocket\n')) + +# YOUR CODE HERE diff --git a/exercises/11-Your-First-If/test.py b/exercises/11-Your-First-If/test.py new file mode 100644 index 00000000..6ae9497a --- /dev/null +++ b/exercises/11-Your-First-If/test.py @@ -0,0 +1,28 @@ +# from app import my_function +import pytest,os,re,io,sys, mock, json + +@pytest.mark.it("1. The console should return the correct string for each condition") +def test_t(stdin): + _input = json.loads(stdin) + print("####", _input) + with mock.patch('builtins.input', lambda x: _input[0]): + if int(_input[0]) > 100: + # f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + sys.stdout = buffer = io.StringIO() + import app + + assert "Give me your money!\n" == buffer.getvalue() + elif int(_input[0]) < 100 and int(_input[0]) > 50: + sys.stdout = buffer = io.StringIO() + import app + + assert "Buy me some coffee you cheap!\n" == buffer.getvalue() + elif int(_input[0]) < 50: + sys.stdout = buffer = io.StringIO() + import app + + assert "You are a poor guy, go away!\n" == buffer.getvalue() + + + + diff --git a/exercises/12-How-Much-The-Wedding-Costs/README.md b/exercises/12-How-Much-The-Wedding-Costs/README.md new file mode 100644 index 00000000..584ae8cb --- /dev/null +++ b/exercises/12-How-Much-The-Wedding-Costs/README.md @@ -0,0 +1,21 @@ +# `12` How Much The Wedding Costs (if...else) + +Here is a table of prices for a wedding catering company: + +Up to 50 people $4,000 +Up to 100 people $10,000 +Up to 200 people $15,000 +More than 200 people $20,000 + + + +## 📝 Instructions: + +1. Please write an algorithm that prompts the user for the number of people attending +their wedding and prints the corresponding price in the console. + +For example, if the user says that 20 people are attending to the wedding, it must cost $4,000 dollars. + +## 💡 Hint: + +Use if/else to divide your code and set the value of the price variable the right way. diff --git a/exercises/12-How-Much-The-Wedding-Costs/app.py b/exercises/12-How-Much-The-Wedding-Costs/app.py new file mode 100644 index 00000000..6550b341 --- /dev/null +++ b/exercises/12-How-Much-The-Wedding-Costs/app.py @@ -0,0 +1,7 @@ +user_input = int(input('How many people are coming to your wedding?\n')) + + + + +# Your code above here +print('Your wedding will cost '+str(price)+' dollars') \ No newline at end of file diff --git a/exercises/12-How-Much-The-Wedding-Costs/test.py b/exercises/12-How-Much-The-Wedding-Costs/test.py new file mode 100644 index 00000000..64b25e89 --- /dev/null +++ b/exercises/12-How-Much-The-Wedding-Costs/test.py @@ -0,0 +1,31 @@ +# from app import my_function +import pytest,os,re,io,sys, mock, json + +@pytest.mark.it("1. The console should return the correct string for each condition") +def test_t(stdin): + _input = json.loads(stdin) + print("####", _input) + with mock.patch('builtins.input', lambda x: _input[0]): + if int(_input[0]) > 100 and int(_input[0]) < 200: + # f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + sys.stdout = buffer = io.StringIO() + import app + price = 15000 + + "Your wedding will cost "+str(price)+" dollars\n" == buffer.getvalue() + elif int(_input[0]) < 101 and int(_input[0]) > 50: + sys.stdout = buffer = io.StringIO() + import app + price = 10000 + + assert "Your wedding will cost "+str(price)+" dollars\n" == buffer.getvalue() + elif int(_input[0]) < 50: + sys.stdout = buffer = io.StringIO() + import app + price = 4000 + "Your wedding will cost "+str(price)+" dollars\n" == buffer.getvalue() + elif int(_input[0]) > 200: + sys.stdout = buffer = io.StringIO() + import app + price = 20000 + "Your wedding will cost "+str(price)+" dollars\n" == buffer.getvalue() diff --git a/exercises/13-Random-Numbers/README.md b/exercises/13-Random-Numbers/README.md new file mode 100644 index 00000000..b2e808a8 --- /dev/null +++ b/exercises/13-Random-Numbers/README.md @@ -0,0 +1,13 @@ +# `13` Random Numbers + +You can use the **randint()** function to get a random integer number. **randint()** is an inbuilt function of the random module in Python3. +The random module gives access to various useful functions and one of them being able to generate random numbers, which is **randint()**. + +The code now is returning random decimal numbers. + +## 📝 Instructions: + +1. Now, please update the function code to make it return an integer (no decimals) number between 1 and 10. + + + diff --git a/exercises/13-Random-Numbers/app.py b/exercises/13-Random-Numbers/app.py new file mode 100644 index 00000000..aeefd3f7 --- /dev/null +++ b/exercises/13-Random-Numbers/app.py @@ -0,0 +1,10 @@ +import random + +def get_randomInt(): + # CHANGE ONLY THIS LINE BELOW + random_number = random.random() + return random_number + + + +print(get_randomInt()) \ No newline at end of file diff --git a/exercises/13-Random-Numbers/test.py b/exercises/13-Random-Numbers/test.py new file mode 100644 index 00000000..a0f9fb40 --- /dev/null +++ b/exercises/13-Random-Numbers/test.py @@ -0,0 +1,19 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import os +import re + +@pytest.mark.it("1. You should update only line 5 using randint()") +def test_conditional(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "random_number =" in s] + my_printVar = content.index(my_print[0]) + regex = r"random_number(\s*)=(\s*)random\.rand\w+\(1,10\)" + assert re.match(regex, content[my_printVar]) + diff --git a/exercises/14-Rand-From-One-to-Six/README.md b/exercises/14-Rand-From-One-to-Six/README.md new file mode 100644 index 00000000..7e40dc6e --- /dev/null +++ b/exercises/14-Rand-From-One-to-Six/README.md @@ -0,0 +1,14 @@ +# `14` Rand From 0 to 12 + + +## 📝 Instructions: + +1. Okay, now change whatever you need to change to make the algorithm print random integers between 1 and 12. +This time use **randrange()** + +## 💡 Hint: + +- It should print between 1 and 12, not between 0 and 12. +- This exercise is super simple, don't over complicate things.... + + diff --git a/exercises/14-Rand-From-One-to-Six/app.py b/exercises/14-Rand-From-One-to-Six/app.py new file mode 100644 index 00000000..0e29fa95 --- /dev/null +++ b/exercises/14-Rand-From-One-to-Six/app.py @@ -0,0 +1,9 @@ +import random + +def get_randomInt(): + random_number = random.randint(1,10) + return random_number + + + +print(get_randomInt()) \ No newline at end of file diff --git a/exercises/14-Rand-From-One-to-Six/test.py b/exercises/14-Rand-From-One-to-Six/test.py new file mode 100644 index 00000000..92b35a92 --- /dev/null +++ b/exercises/14-Rand-From-One-to-Six/test.py @@ -0,0 +1,19 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import os +import app +import re + +@pytest.mark.it("1. You should return a random number between 1 and 12 included") +def test_conditional(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "random_number =" in s] + my_printVar = content.index(my_print[0]) + regex = r"random_number(\s*)=(\s*)random\.randrange+\(13\)" + assert re.match(regex, content[my_printVar]) diff --git a/exercises/15-Your-First-Loop/README.md b/exercises/15-Your-First-Loop/README.md new file mode 100644 index 00000000..f25ce53b --- /dev/null +++ b/exercises/15-Your-First-Loop/README.md @@ -0,0 +1,7 @@ +# `15` Your First Loop + +If you run this code you'll see a count from 0 to 99 (White characters). Fix it so that it counts up to 100, you'll see 101 on green afterwards. + +IMPORTANT: there's a Classroom dedicated to Arrays, we encourage you to go and finish those after this first Array exercise. (And then, come back). + +**Can you fix it?** diff --git a/exercises/15-Your-First-Loop/app.py b/exercises/15-Your-First-Loop/app.py new file mode 100644 index 00000000..0ffee236 --- /dev/null +++ b/exercises/15-Your-First-Loop/app.py @@ -0,0 +1,6 @@ +def start_counting(): + for i in range(100): + print(i) + return i + +start_counting() \ No newline at end of file diff --git a/exercises/15-Your-First-Loop/test.py b/exercises/15-Your-First-Loop/test.py new file mode 100644 index 00000000..8e301955 --- /dev/null +++ b/exercises/15-Your-First-Loop/test.py @@ -0,0 +1,20 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import os +import app +import re + + +@pytest.mark.it("1. You should return a list of number between 0 and 100") +def test_conditional(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "for" in s] + my_printVar = content.index(my_print[0]) + regex = r"for i in range\(101\):" + assert re.match(regex, content[my_printVar]) \ No newline at end of file diff --git a/exercises/16-Create-A-For-Loop/README.md b/exercises/16-Create-A-For-Loop/README.md new file mode 100644 index 00000000..cd6985da --- /dev/null +++ b/exercises/16-Create-A-For-Loop/README.md @@ -0,0 +1,20 @@ +# `16` Create A For Loop + +Loops are very useful, you don't have to repeat yourself by writing the same lines many times. + +The "**for**" loop lets you run the same code for different values. + +Read more on loops: +```sh +https://www.w3schools.com/python/python_for_loops.asp +``` + +## 📝 Instructions: + +1. Create a function called **standards_maker** +2. The function has to print 300 times the phrase "I will write questions if I am stuck". +3. Call the finction **standards_maker()** + +## 💡 Hint: + +- You can use the range() function in the for loop. \ No newline at end of file diff --git a/exercises/16-Create-A-For-Loop/app.py b/exercises/16-Create-A-For-Loop/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/16-Create-A-For-Loop/test.py b/exercises/16-Create-A-For-Loop/test.py new file mode 100644 index 00000000..d7f8eff5 --- /dev/null +++ b/exercises/16-Create-A-For-Loop/test.py @@ -0,0 +1,47 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import os +import app +import re + +@pytest.mark.it("1. You should declare a function named standards_maker") +def test_function_name(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "def standards_maker():" in s] + my_printVar = content.index(my_print[0]) + regex = r"def standards_maker\(\):" + assert re.match(regex, content[my_printVar]) + +@pytest.mark.it("2. You should include in the function standards_maker a for loop which prints the string in the instructions 300 times") +def test_print(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_for = [s for s in content if "for x in range(300):" in s] + my_forVar = content.index(my_for[0]) + regex_for = r"for x in range\(300\):" + my_print = [s for s in content if 'print("I will write questions if I am stuck")' in s] + my_printVar = content.index(my_print[0]) + regex_print = r"print\(\"I will write questions if I am stuck\"\)" + + assert re.match(regex_for, content[my_forVar]) + assert re.match(regex_print, content[my_printVar]) + +@pytest.mark.it("3. You should call the function standards_maker ") +def test_callTheFunction(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_call = [s for s in content[2:] if "standards_maker()" in s] + my_callVar = content.index(my_call[0]) + print("###",my_callVar) + regex_call = r"standards_maker\(\)" + + + assert re.match(regex_call, content[my_callVar]) diff --git a/exercises/17-While-Loop/README.md b/exercises/17-While-Loop/README.md new file mode 100644 index 00000000..f5d6642a --- /dev/null +++ b/exercises/17-While-Loop/README.md @@ -0,0 +1,12 @@ +# `17` While Loop + +This code is broken, it produces an infinite loop. Replit handles the infinite loop, for now. + +Fix the problem, to print from 100 - 0. And return 0. + +## 💡 Hint: + +- To stop the infinite loop press **ctrl + c** (It could take a while before it stops, be patient!)and then run again **bc run:exercises -e=gitpod** + + +IMPORTANT: there's a Classroom Exercise dedicated to Arrays, we encourage you to go and finish those after this first Array exercise. (And then, come back). diff --git a/exercises/17-While-Loop/app.py b/exercises/17-While-Loop/app.py new file mode 100644 index 00000000..84b0e9db --- /dev/null +++ b/exercises/17-While-Loop/app.py @@ -0,0 +1,7 @@ +def start_counting(): + counter = 100 + while counter <= 100: + print(counter) + counter-=1 + return counter +start_counting() \ No newline at end of file diff --git a/exercises/17-While-Loop/test.py b/exercises/17-While-Loop/test.py new file mode 100644 index 00000000..c205ff23 --- /dev/null +++ b/exercises/17-While-Loop/test.py @@ -0,0 +1,29 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import os +import app +import re +@pytest.mark.it("1. You should declare a function named standards_maker") +def test_while_loop(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_while = [s for s in content if "while counter > -1:" in s] + my_whileVar = content.index(my_while[0]) + regex = r"while counter(\s*)>(\s*)-1:" + assert re.match(regex, content[my_whileVar]) + +# @pytest.mark.it('2. The console should print numbers from 100 to 1') +# def test_for_file_output(capsys): +# def test(): +# counter = 100 +# while counter > 0: +# print(counter) +# counter-=1 +# return counter +# captured = buffer.getvalue() +# assert captured == str(test())+'\n' \ No newline at end of file diff --git a/exercises/18-Random-Colors-Loop/README.md b/exercises/18-Random-Colors-Loop/README.md new file mode 100644 index 00000000..efca924a --- /dev/null +++ b/exercises/18-Random-Colors-Loop/README.md @@ -0,0 +1,19 @@ +# `18` Random Colors (Loop) + +We have created a function that returns a color based on a number between 1 and 4 (for any different number, it will return the color black). + +## 📝 Instructions: + +Let's say that we are teachers in a 10 student classroom and we want to randomly assign ONE color, between red, yellow, blue and green, to EACH student. + +(only ONE color PER student) + +1. Change the function "**get_allStudentColors**" so it returns an array of 10 colors, with each item in the array representing the color assigned to each student. + +## 💡 Hint: + +- You have 10 students, you need to loop 10 times. +- Each time you loop, generate a random number between 1-4 using the **randint()** function we saw on the last exercise. +- Use the "**get_color**" function on this exercise to get the color name from the number you get. +- Print the color on the console. + diff --git a/exercises/18-Random-Colors-Loop/app.py b/exercises/18-Random-Colors-Loop/app.py new file mode 100644 index 00000000..3902cf0f --- /dev/null +++ b/exercises/18-Random-Colors-Loop/app.py @@ -0,0 +1,27 @@ +import random + +def get_color(color_number=4): + # making sure is a number and not a string + color_number = int(color_number) + + switcher={ + 0:'red', + 1:'yellow', + 2:'blue', + 3:'green', + 4:'black' + } + return switcher.get(color_number,"Invalid Color Number") + + +def get_allStudentColors(): + + example_color = 1 + students_array = [] + #your loop here + + + + + +print(get_allStudentColors()) \ No newline at end of file diff --git a/exercises/18-Random-Colors-Loop/test.py b/exercises/18-Random-Colors-Loop/test.py new file mode 100644 index 00000000..57544005 --- /dev/null +++ b/exercises/18-Random-Colors-Loop/test.py @@ -0,0 +1,29 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import app +import os +import re + +@pytest.mark.it('STEP 3. Your code needs to print the correct output on the console') +def test_for_file_output(capsys): + captured = buffer.getvalue() + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + print("@@@@", content) + regex = r"print\(get_allStudentColors\(\)\)" + assert re.match(regex, content[(len(content)-1)]) + +# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') +# def test_for_function_output(capsys): +# my_function() +# captured = capsys.readouterr() +# assert captured.out == "Hello Inside Function\n" + +# @pytest.mark.it('Your function needs to return True') +# def test_for_function_return(capsys): +# assert my_function() == True \ No newline at end of file diff --git a/exercises/19-Looping-With-FizzBuzz/README.md b/exercises/19-Looping-With-FizzBuzz/README.md new file mode 100644 index 00000000..9ed5f7a8 --- /dev/null +++ b/exercises/19-Looping-With-FizzBuzz/README.md @@ -0,0 +1,44 @@ +# `19` Looping With FizzBuzz + +This is a typical beginner test that is required to complete interviews in Google, Facebook and all the other big tech unicorns. + + +## 📝 Instructions: +Write the code needed to print in the console all the numbers from 1 to 100. +1. For multiples of 3, instead of the number, print "Fizz". +2. For multiples of 5, print "Buzz". +3. For numbers which are multiples of both 3 and 5, print "FizzBuzz". + +Example output: + +```py + +1 +2 +Fizz +4 +Buzz +Fizz +7 +8 +Fizz +Buzz +11 +Fizz +13 +14 +FizzBuzz +16 +.... +.... +98 +Fizz +Buzz + + +``` + + +## 💡 Hint: + +- It's recommended to do the Arrays Exercises before this exercise. diff --git a/exercises/19-Looping-With-FizzBuzz/app.py b/exercises/19-Looping-With-FizzBuzz/app.py new file mode 100644 index 00000000..daab9805 --- /dev/null +++ b/exercises/19-Looping-With-FizzBuzz/app.py @@ -0,0 +1,5 @@ +def fizz_buzz(): + # your code here + + +fizz_buzz() \ No newline at end of file diff --git a/exercises/19-Looping-With-FizzBuzz/test.py b/exercises/19-Looping-With-FizzBuzz/test.py new file mode 100644 index 00000000..e6b90445 --- /dev/null +++ b/exercises/19-Looping-With-FizzBuzz/test.py @@ -0,0 +1,29 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() +from app import fizz_buzz +# from app import my_function +import pytest +import app +import os +import re + +@pytest.mark.it("1. Don't change or remove the existing code") +def test_forExistingCode(capsys): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_code = [s for s in content if "def fizz_buzz():" in s] + my_codeVar = content.index(my_code[0]) + regex = r"def fizz_buzz\(\):" + my_codeCall = [s for s in content[3:] if "fizz_buzz()" in s] + my_codeCallVar = content.index(my_codeCall[0]) + regexCall = r"fizz_buzz\(\)" + + assert re.match(regex, content[my_codeVar]) + assert re.match(regexCall, content[my_codeCallVar]) +@pytest.mark.it('2. Your function needs to print the correct output') +def test_for_function_output(capsys): + fizz_buzz() + captured = capsys.readouterr() + assert captured.out == "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz\n" diff --git a/exercises/20-Russian-Roulette/README.md b/exercises/20-Russian-Roulette/README.md new file mode 100644 index 00000000..92e78bec --- /dev/null +++ b/exercises/20-Russian-Roulette/README.md @@ -0,0 +1,19 @@ +# `20` Russian Roulette + +Have you ever played Russian Roulette? It's super fun! If you make it (wuuuajajajaja). + +The revolver gun has only 6 slots for bullets... insert one bullet in one of the slots, +spin the revolver chamber to make the game random, nobody knows the bullet position. + +FIRE!!!....... are you dead? + + +## 📝 Instructions: +1. The game is almost working, please fill the function "**fire_gun**" to make the game work +(compare the bullet position against the chamber position.) + + +## 💡 Hint: + +- The function needs to return **You are dead!** or **Keep playing!** depending on the result, if the bullet was +at the same slot as the revolver chamber, then it will be fired (**You are dead!**). diff --git a/exercises/20-Russian-Roulette/app.py b/exercises/20-Russian-Roulette/app.py new file mode 100644 index 00000000..664d81ed --- /dev/null +++ b/exercises/20-Russian-Roulette/app.py @@ -0,0 +1,16 @@ +import random + +bullet_position = 3 + +def spin_chamber(): + chamber_position = random.randint(1,6) + return chamber_position + +# DON'T CHANGE THE CODE ABOVE +def fire_gun(): + # YOUR CODE HERE + + + + +print(fire_gun()) \ No newline at end of file diff --git a/exercises/20-Russian-Roulette/test.py b/exercises/20-Russian-Roulette/test.py new file mode 100644 index 00000000..35ddd0ea --- /dev/null +++ b/exercises/20-Russian-Roulette/test.py @@ -0,0 +1,22 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import app +import re +import os + + +@pytest.mark.it('1. Your code needs to print the correct output on the console') +def test_for_file_output(capsys): + + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_codeCall = [s for s in content[3:] if "print(fire_gun())" in s] + my_codeCallVar = content.index(my_codeCall[0]) + regex = r"print\(fire_gun\(\)\)" + assert re.match(regex, content[my_codeCallVar]) + diff --git a/exercises/21-The-Beatles/README.md b/exercises/21-The-Beatles/README.md new file mode 100644 index 00000000..7f8b1c63 --- /dev/null +++ b/exercises/21-The-Beatles/README.md @@ -0,0 +1,33 @@ +# `21` The Beatles + +Who does not like The Beatles? +A BBC study has proved that 90% of kids don't know the band.. so sad.. :( + +This is the chorus of one of the most famous Beatle songs: + +> Let it be, let it be, let it be, let it be +> Whisper words of wisdom +> Let it be + +## 📝 Instructions: +1. Create a function called **sing()** +2. The function needs to **print** (use the print statement and no return) a string with the exact same lyrics +you can hear from the 3:10 sec to the end of the song at 3:54 sec. +Here is the expected output: + +```sh +let it be, +let it be, +let it be, +let it be, +whisper words of wisdom, let it be, let it be, +let it be, +let it be, +let it be, +there will be an answer, let it be +``` +(https://www.youtube.com/watch?v=2xDzVZcqtYI) + +## 💡 Hint: + +- The words "let it be" repeat all the time, probably you should create a loop for that. diff --git a/exercises/21-The-Beatles/app.py b/exercises/21-The-Beatles/app.py new file mode 100644 index 00000000..0baf074f --- /dev/null +++ b/exercises/21-The-Beatles/app.py @@ -0,0 +1,6 @@ +# Your code here!! + + + + + diff --git a/exercises/21-The-Beatles/test.py b/exercises/21-The-Beatles/test.py new file mode 100644 index 00000000..66e1f46f --- /dev/null +++ b/exercises/21-The-Beatles/test.py @@ -0,0 +1,30 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() +from app import sing + +import pytest +import os +import app +import re + + +@pytest.mark.it("1. You should declare a function named sing and call it in the correct way") +def test_functionSing(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_funcName = [s for s in content if "def sing():" in s] + my_funcNameVar = content.index(my_funcName[0]) + regex = r"def sing\(\):" + my_print = [s for s in content[2:] if "sing()" in s] + my_printVar = content.index(my_print[0]) + regexPrint = r"sing\(\)" + assert re.match(regex, content[my_funcNameVar]) + assert re.match(regexPrint, content[my_printVar]) + +@pytest.mark.it('2. Your function needs to print the correct output') +def test_for_function_output(capsys): + sing() + captured = capsys.readouterr() + assert captured.out == "let it be,\nlet it be,\nlet it be,\nlet it be,\nwhisper words of wisdom, let it be, let it be,\nlet it be,\nlet it be,\nlet it be,\nthere will be an answer, let it be\n" \ No newline at end of file diff --git a/exercises/22-Bottles-Of-Milk/README.md b/exercises/22-Bottles-Of-Milk/README.md new file mode 100644 index 00000000..ba2f2d08 --- /dev/null +++ b/exercises/22-Bottles-Of-Milk/README.md @@ -0,0 +1,32 @@ +# `22` Bottles Of Milk + +Have you heard the song about 99 bottles of milk? Is a great song, is not boring at all... +here you can here it: https://www.youtube.com/watch?v=Xy-da43E6Lo + + +## 📝 Instructions: +1. Please declare a function named **number_of_bottles()** +2. The function needs to **print** (use the print statement and no return) the exact same lyrics in the song. + + +## 💡 Hint: + +- At the end of the song, the lyrics change because is only one bottle (singular instead of plural). +- Read the last lyrics and you will see how the last line changes to "go to the store and by some more". + +The result should be something like this: + +```sh +99 bottles of milk on the wall, 99 bottles of milk. +Take one down and pass it around, 98 bottles of milk on the wall. + +98 bottles of milk on the wall, 98 bottles of milk. +Take one down and pass it around, 97 bottles of milk on the wall. +... +... +1 bottle of milk on the wall, 1 bottle of milk. +Take one down and pass it around, no more bottles of milk on the wall. + +No more bottles of milk on the wall, no more bottles of milk. +Go to the store and buy some more, 99 bottles of milk on the wall. +``` diff --git a/exercises/22-Bottles-Of-Milk/app.py b/exercises/22-Bottles-Of-Milk/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/22-Bottles-Of-Milk/test.py b/exercises/22-Bottles-Of-Milk/test.py new file mode 100644 index 00000000..8bbbff10 --- /dev/null +++ b/exercises/22-Bottles-Of-Milk/test.py @@ -0,0 +1,244 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() +from app import number_of_bottles +# from app import my_function +import pytest +import os +import app +import re + +@pytest.mark.it('1. You need to declare a function called number_of_bottles that print the correct lyrics, and calling it correctly') +def test_for_file_output(capsys): + + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + my_funcCall = [s for s in content if "def number_of_bottles():" in s] + my_funcCallVar = content.index(my_funcCall[0]) + regex = r"def number_of_bottles\(\):" + assert re.match(regex, content[my_funcCallVar]) + my_printCall = [s for s in content[3:] if "number_of_bottles()" in s] + my_printCallVar = content.index(my_printCall[0]) + regex = r"number_of_bottles\(\)" + assert re.match(regex, content[my_printCallVar]) +@pytest.mark.it('2. Your function needs to print the correct output') +def test_for_function_output(capsys): + number_of_bottles() + captured = capsys.readouterr() + print("@@@@", captured.out) + assert captured.out == """99 bottles of milk on the wall, 99 bottles of milk. +Take one down and pass it around, 98 bottles of milk on the wall. +98 bottles of milk on the wall, 98 bottles of milk. +Take one down and pass it around, 97 bottles of milk on the wall. +97 bottles of milk on the wall, 97 bottles of milk. +Take one down and pass it around, 96 bottles of milk on the wall. +96 bottles of milk on the wall, 96 bottles of milk. +Take one down and pass it around, 95 bottles of milk on the wall. +95 bottles of milk on the wall, 95 bottles of milk. +Take one down and pass it around, 94 bottles of milk on the wall. +94 bottles of milk on the wall, 94 bottles of milk. +Take one down and pass it around, 93 bottles of milk on the wall. +93 bottles of milk on the wall, 93 bottles of milk. +Take one down and pass it around, 92 bottles of milk on the wall. +92 bottles of milk on the wall, 92 bottles of milk. +Take one down and pass it around, 91 bottles of milk on the wall. +91 bottles of milk on the wall, 91 bottles of milk. +Take one down and pass it around, 90 bottles of milk on the wall. +90 bottles of milk on the wall, 90 bottles of milk. +Take one down and pass it around, 89 bottles of milk on the wall. +89 bottles of milk on the wall, 89 bottles of milk. +Take one down and pass it around, 88 bottles of milk on the wall. +88 bottles of milk on the wall, 88 bottles of milk. +Take one down and pass it around, 87 bottles of milk on the wall. +87 bottles of milk on the wall, 87 bottles of milk. +Take one down and pass it around, 86 bottles of milk on the wall. +86 bottles of milk on the wall, 86 bottles of milk. +Take one down and pass it around, 85 bottles of milk on the wall. +85 bottles of milk on the wall, 85 bottles of milk. +Take one down and pass it around, 84 bottles of milk on the wall. +84 bottles of milk on the wall, 84 bottles of milk. +Take one down and pass it around, 83 bottles of milk on the wall. +83 bottles of milk on the wall, 83 bottles of milk. +Take one down and pass it around, 82 bottles of milk on the wall. +82 bottles of milk on the wall, 82 bottles of milk. +Take one down and pass it around, 81 bottles of milk on the wall. +81 bottles of milk on the wall, 81 bottles of milk. +Take one down and pass it around, 80 bottles of milk on the wall. +80 bottles of milk on the wall, 80 bottles of milk. +Take one down and pass it around, 79 bottles of milk on the wall. +79 bottles of milk on the wall, 79 bottles of milk. +Take one down and pass it around, 78 bottles of milk on the wall. +78 bottles of milk on the wall, 78 bottles of milk. +Take one down and pass it around, 77 bottles of milk on the wall. +77 bottles of milk on the wall, 77 bottles of milk. +Take one down and pass it around, 76 bottles of milk on the wall. +76 bottles of milk on the wall, 76 bottles of milk. +Take one down and pass it around, 75 bottles of milk on the wall. +75 bottles of milk on the wall, 75 bottles of milk. +Take one down and pass it around, 74 bottles of milk on the wall. +74 bottles of milk on the wall, 74 bottles of milk. +Take one down and pass it around, 73 bottles of milk on the wall. +73 bottles of milk on the wall, 73 bottles of milk. +Take one down and pass it around, 72 bottles of milk on the wall. +72 bottles of milk on the wall, 72 bottles of milk. +Take one down and pass it around, 71 bottles of milk on the wall. +71 bottles of milk on the wall, 71 bottles of milk. +Take one down and pass it around, 70 bottles of milk on the wall. +70 bottles of milk on the wall, 70 bottles of milk. +Take one down and pass it around, 69 bottles of milk on the wall. +69 bottles of milk on the wall, 69 bottles of milk. +Take one down and pass it around, 68 bottles of milk on the wall. +68 bottles of milk on the wall, 68 bottles of milk. +Take one down and pass it around, 67 bottles of milk on the wall. +67 bottles of milk on the wall, 67 bottles of milk. +Take one down and pass it around, 66 bottles of milk on the wall. +66 bottles of milk on the wall, 66 bottles of milk. +Take one down and pass it around, 65 bottles of milk on the wall. +65 bottles of milk on the wall, 65 bottles of milk. +Take one down and pass it around, 64 bottles of milk on the wall. +64 bottles of milk on the wall, 64 bottles of milk. +Take one down and pass it around, 63 bottles of milk on the wall. +63 bottles of milk on the wall, 63 bottles of milk. +Take one down and pass it around, 62 bottles of milk on the wall. +62 bottles of milk on the wall, 62 bottles of milk. +Take one down and pass it around, 61 bottles of milk on the wall. +61 bottles of milk on the wall, 61 bottles of milk. +Take one down and pass it around, 60 bottles of milk on the wall. +60 bottles of milk on the wall, 60 bottles of milk. +Take one down and pass it around, 59 bottles of milk on the wall. +59 bottles of milk on the wall, 59 bottles of milk. +Take one down and pass it around, 58 bottles of milk on the wall. +58 bottles of milk on the wall, 58 bottles of milk. +Take one down and pass it around, 57 bottles of milk on the wall. +57 bottles of milk on the wall, 57 bottles of milk. +Take one down and pass it around, 56 bottles of milk on the wall. +56 bottles of milk on the wall, 56 bottles of milk. +Take one down and pass it around, 55 bottles of milk on the wall. +55 bottles of milk on the wall, 55 bottles of milk. +Take one down and pass it around, 54 bottles of milk on the wall. +54 bottles of milk on the wall, 54 bottles of milk. +Take one down and pass it around, 53 bottles of milk on the wall. +53 bottles of milk on the wall, 53 bottles of milk. +Take one down and pass it around, 52 bottles of milk on the wall. +52 bottles of milk on the wall, 52 bottles of milk. +Take one down and pass it around, 51 bottles of milk on the wall. +51 bottles of milk on the wall, 51 bottles of milk. +Take one down and pass it around, 50 bottles of milk on the wall. +50 bottles of milk on the wall, 50 bottles of milk. +Take one down and pass it around, 49 bottles of milk on the wall. +49 bottles of milk on the wall, 49 bottles of milk. +Take one down and pass it around, 48 bottles of milk on the wall. +48 bottles of milk on the wall, 48 bottles of milk. +Take one down and pass it around, 47 bottles of milk on the wall. +47 bottles of milk on the wall, 47 bottles of milk. +Take one down and pass it around, 46 bottles of milk on the wall. +46 bottles of milk on the wall, 46 bottles of milk. +Take one down and pass it around, 45 bottles of milk on the wall. +45 bottles of milk on the wall, 45 bottles of milk. +Take one down and pass it around, 44 bottles of milk on the wall. +44 bottles of milk on the wall, 44 bottles of milk. +Take one down and pass it around, 43 bottles of milk on the wall. +43 bottles of milk on the wall, 43 bottles of milk. +Take one down and pass it around, 42 bottles of milk on the wall. +42 bottles of milk on the wall, 42 bottles of milk. +Take one down and pass it around, 41 bottles of milk on the wall. +41 bottles of milk on the wall, 41 bottles of milk. +Take one down and pass it around, 40 bottles of milk on the wall. +40 bottles of milk on the wall, 40 bottles of milk. +Take one down and pass it around, 39 bottles of milk on the wall. +39 bottles of milk on the wall, 39 bottles of milk. +Take one down and pass it around, 38 bottles of milk on the wall. +38 bottles of milk on the wall, 38 bottles of milk. +Take one down and pass it around, 37 bottles of milk on the wall. +37 bottles of milk on the wall, 37 bottles of milk. +Take one down and pass it around, 36 bottles of milk on the wall. +36 bottles of milk on the wall, 36 bottles of milk. +Take one down and pass it around, 35 bottles of milk on the wall. +35 bottles of milk on the wall, 35 bottles of milk. +Take one down and pass it around, 34 bottles of milk on the wall. +34 bottles of milk on the wall, 34 bottles of milk. +Take one down and pass it around, 33 bottles of milk on the wall. +33 bottles of milk on the wall, 33 bottles of milk. +Take one down and pass it around, 32 bottles of milk on the wall. +32 bottles of milk on the wall, 32 bottles of milk. +Take one down and pass it around, 31 bottles of milk on the wall. +31 bottles of milk on the wall, 31 bottles of milk. +Take one down and pass it around, 30 bottles of milk on the wall. +30 bottles of milk on the wall, 30 bottles of milk. +Take one down and pass it around, 29 bottles of milk on the wall. +29 bottles of milk on the wall, 29 bottles of milk. +Take one down and pass it around, 28 bottles of milk on the wall. +28 bottles of milk on the wall, 28 bottles of milk. +Take one down and pass it around, 27 bottles of milk on the wall. +27 bottles of milk on the wall, 27 bottles of milk. +Take one down and pass it around, 26 bottles of milk on the wall. +26 bottles of milk on the wall, 26 bottles of milk. +Take one down and pass it around, 25 bottles of milk on the wall. +25 bottles of milk on the wall, 25 bottles of milk. +Take one down and pass it around, 24 bottles of milk on the wall. +24 bottles of milk on the wall, 24 bottles of milk. +Take one down and pass it around, 23 bottles of milk on the wall. +23 bottles of milk on the wall, 23 bottles of milk. +Take one down and pass it around, 22 bottles of milk on the wall. +22 bottles of milk on the wall, 22 bottles of milk. +Take one down and pass it around, 21 bottles of milk on the wall. +21 bottles of milk on the wall, 21 bottles of milk. +Take one down and pass it around, 20 bottles of milk on the wall. +20 bottles of milk on the wall, 20 bottles of milk. +Take one down and pass it around, 19 bottles of milk on the wall. +19 bottles of milk on the wall, 19 bottles of milk. +Take one down and pass it around, 18 bottles of milk on the wall. +18 bottles of milk on the wall, 18 bottles of milk. +Take one down and pass it around, 17 bottles of milk on the wall. +17 bottles of milk on the wall, 17 bottles of milk. +Take one down and pass it around, 16 bottles of milk on the wall. +16 bottles of milk on the wall, 16 bottles of milk. +Take one down and pass it around, 15 bottles of milk on the wall. +15 bottles of milk on the wall, 15 bottles of milk. +Take one down and pass it around, 14 bottles of milk on the wall. +14 bottles of milk on the wall, 14 bottles of milk. +Take one down and pass it around, 13 bottles of milk on the wall. +13 bottles of milk on the wall, 13 bottles of milk. +Take one down and pass it around, 12 bottles of milk on the wall. +12 bottles of milk on the wall, 12 bottles of milk. +Take one down and pass it around, 11 bottles of milk on the wall. +11 bottles of milk on the wall, 11 bottles of milk. +Take one down and pass it around, 10 bottles of milk on the wall. +10 bottles of milk on the wall, 10 bottles of milk. +Take one down and pass it around, 9 bottles of milk on the wall. +9 bottles of milk on the wall, 9 bottles of milk. +Take one down and pass it around, 8 bottles of milk on the wall. +8 bottles of milk on the wall, 8 bottles of milk. +Take one down and pass it around, 7 bottles of milk on the wall. +7 bottles of milk on the wall, 7 bottles of milk. +Take one down and pass it around, 6 bottles of milk on the wall. +6 bottles of milk on the wall, 6 bottles of milk. +Take one down and pass it around, 5 bottles of milk on the wall. +5 bottles of milk on the wall, 5 bottles of milk.\nTake one down and pass it around, 4 bottles of milk on the wall. +4 bottles of milk on the wall, 4 bottles of milk. +Take one down and pass it around, 3 bottles of milk on the wall. +3 bottles of milk on the wall, 3 bottles of milk. +Take one down and pass it around, 2 bottles of milk on the wall. +1 bottle of milk on the wall, 1 bottle of milk. +Take one down and pass it around, no more bottles of milk on the wall. +No more bottles of milk on the wall, no more bottles of milk. +Go to the store and buy some more, 99 bottles of milk on the wall.\n""" + # assert captured.out == """5 bottles of milk on the wall, 5 bottles of milk. + # Take one down and pass it around, 4 bottles of milk on the wall. + # 4 bottles of milk on the wall, 4 bottles of milk. + # Take one down and pass it around, 3 bottles of milk on the wall. + # 3 bottles of milk on the wall, 3 bottles of milk. + # Take one down and pass it around, 2 bottles of milk on the wall. + # 1 bottle of milk on the wall, 1 bottle of milk. + # Take one down and pass it around, no more bottles of milk on the wall. + # No more bottles of milk on the wall, no more bottles of milk. + # Go to the store and buy some more, 99 bottles of milk on the wall.""" +# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') +# def test_for_function_output(capsys): +# my_function() +# captured = capsys.readouterr() +# assert captured.out == "Hello Inside Function\n" + +# @pytest.mark.it('Your function needs to return True') +# def test_for_function_return(capsys): +# assert my_function() == True \ No newline at end of file diff --git a/exercises/23-Python-Objects/README.md b/exercises/23-Python-Objects/README.md new file mode 100644 index 00000000..273a2427 --- /dev/null +++ b/exercises/23-Python-Objects/README.md @@ -0,0 +1,79 @@ +# `23` Python Objects + +Often you'll find yourself wanting to save more information in less space, especially if it's all related. For example: + +Let's say that we want to represent cars into variables: + +```py +car_1_Model = "corolla" +car_1_Make = "Toyota" +car_1_Color = "green" +car_1_Year = 2015 + +car_2_Model = "santa fe" +car_2_Make = "Hyundai" +car_2_Color = "purple" +car_2_Year = 2013 +#... (you get the idea) +``` + +There's an optimized approach to this, it is called Objects. Objects are a type of variable that contains information (other variables) in a key: value manner. + +So if we want to translate (and optimize) the variables from the car into an Object, we do: + +```py +class ClassName: + def __init__(): + self.model = "Corolla" + self.make = "Toyota" + self.color = "Green" + self.year = "2015" + +``` + + +Looks like a function, right? But it's not. + +Now we are storing information into a more organized way, and if we want to get that information we can do: + +```py + +class Person: + def __init__(): + self.name = "John" #String + self.lastname = "Doe" + self.age = 35 #Number + self.gender = "male" + self.lucky_numbers = [ 7, 11, 13, 17] #Array + self.significant_other = person2 #Object, yes the same variable/object defined after + +class Person2: + def __init__(): + self.name = "Jane" + self.lastname = "Doe" + self.age = 38 + self.gender = "female" + self.lucky_numbers = [ 2, 4, 6, 8] + + +class Family: + def __init__(): + self.lastname = "Doe" + self.members = [person, person2] //Array of objects + +``` +So, if on this scenario if we want to know the name of the first member of the Doe family we do: + +```py +print(family.members[0].name) +``` + + +Easy stuff :) +## 📝 Instructions: +1. **1** Programmatically, change the fourth lucky number of John Doe to 33 (use a command, don't manually change the code) +2. **2** Programmatically, create a new person and add it to the family object. Jimmy Doe, 13, male, lucky numbers: 1, 2, 3, 4; significant other: null. (use a command, don't manually change the code) +3. **3** Loop through all the family members to get all the lucky numbers. +3. **4** Now please print ( console.log() ) the SUM of all of the lucky numbers of the Doe family. + + diff --git a/exercises/23-Python-Objects/app.py b/exercises/23-Python-Objects/app.py new file mode 100644 index 00000000..3b765a8c --- /dev/null +++ b/exercises/23-Python-Objects/app.py @@ -0,0 +1,41 @@ +class Person: + name = "John" + lastname = "Doe" + age = 35 + gender = "male" + lucky_numbers = [ 7, 11, 13, 17] + + +class Person_2: + name = "Jane" + lastname = "Doe" + age = 38 + gender = "female" + lucky_numbers = [ 2, 4, 6, 8] + +class Family: + lastname = "Doe" + members = [Person, Person_2] #Array of objects, don't forget to add Jimmy + + + +# STEP 1 Change the fourth lucky number of John Doe to 33 +# Your code here + + +# STEP 2 Create Little Jimmy's object and then add it to the family object +# Your code here + + + +def add_allFamilyLuckyNumbers(an_array): + sum_ofAllLuckyNumbers = 0 # sum_ofAllLuckyNumbers is a number, the sum of all lucky numbers. + + # STEP 3 Loop through all the family members to get all the lucky numbers + # Your code here + + return sum_ofAllLuckyNumbers + +# STEP 4 Print the sum of all the lucky numbers of the Doe's family +# Your code here + diff --git a/exercises/23-Python-Objects/test.py b/exercises/23-Python-Objects/test.py new file mode 100644 index 00000000..05f01659 --- /dev/null +++ b/exercises/23-Python-Objects/test.py @@ -0,0 +1,56 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +# from app import my_function +import pytest +import app +import os +import re + + + + +@pytest.mark.it('1. You should change the fourth lucky number of John Doe!') +def test_forLuckyNumber(capsys): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "Person.lucky_numbers" in s] + my_printVar = content.index(my_print[0]) + regex = r"Person\.lucky_numbers\[3](\s*)=(\s*)33" + assert re.match(regex, content[my_printVar]) +@pytest.mark.it('2. You should create a new person and then add it to the familoy object') +def test_forFamilyMember(capsys): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "Family.members.append" in s] + my_printVar = content.index(my_print[0]) + regex = r"Family\.members\.append\(\w+\)" + assert re.match(regex, content[my_printVar]) + +@pytest.mark.it('3. Your code needs to print the SUM of all the lucky numbers of the Doe family on the console') +def test_for_file_output(capsys): + captured = buffer.getvalue() + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + my_print = [s for s in content if "print(add_allFamilyLuckyNumbers(Family.members))" in s] + my_printVar = content.index(my_print[0]) + regex = r"print\(add_allFamilyLuckyNumbers\(Family\.members\)\)" + assert re.match(regex, content[my_printVar]) + assert captured == str(94)+"\n" + + + # assert captured == str(94)+'\n' + +# @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') +# def test_for_function_output(capsys): +# my_function() +# captured = capsys.readouterr() +# assert captured.out == "Hello Inside Function\n" + +# @pytest.mark.it('Your function needs to return True') +# def test_for_function_return(capsys): +# assert my_function() == True \ No newline at end of file diff --git a/exercises/02-hello-world/README.md b/exercises/26-hello-world/README.md similarity index 100% rename from exercises/02-hello-world/README.md rename to exercises/26-hello-world/README.md diff --git a/exercises/02-hello-world/app.py b/exercises/26-hello-world/app.py similarity index 100% rename from exercises/02-hello-world/app.py rename to exercises/26-hello-world/app.py diff --git a/exercises/02-hello-world/test.py b/exercises/26-hello-world/test.py similarity index 100% rename from exercises/02-hello-world/test.py rename to exercises/26-hello-world/test.py