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