From 906fbcfdbce44700cd0fcd87bd6ae81f348e3983 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 18 Sep 2019 14:26:13 +0000 Subject: [PATCH 01/87] initialized project and exercise 01 --- .../{01-welcome => 00-Welcome}/README.md | 0 exercises/01-Console/README.md | 19 +++++++++++++++++ .../test.py => 01-Console/app.py} | 0 exercises/01-Console/test.py | 0 .../README.md | 0 .../{02-hello-world => 26-hello-world}/app.py | 0 exercises/26-hello-world/test.py | 21 +++++++++++++++++++ 7 files changed, 40 insertions(+) rename exercises/{01-welcome => 00-Welcome}/README.md (100%) create mode 100644 exercises/01-Console/README.md rename exercises/{02-hello-world/test.py => 01-Console/app.py} (100%) create mode 100644 exercises/01-Console/test.py rename exercises/{02-hello-world => 26-hello-world}/README.md (100%) rename exercises/{02-hello-world => 26-hello-world}/app.py (100%) create mode 100644 exercises/26-hello-world/test.py diff --git a/exercises/01-welcome/README.md b/exercises/00-Welcome/README.md similarity index 100% rename from exercises/01-welcome/README.md rename to exercises/00-Welcome/README.md diff --git a/exercises/01-Console/README.md b/exercises/01-Console/README.md new file mode 100644 index 00000000..eacb806d --- /dev/null +++ b/exercises/01-Console/README.md @@ -0,0 +1,19 @@ +# `01` Console + +In JavaScript, we use console.log 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: +```js +console.log("How are you?"); +``` + +## πŸ“ Instructions: + +Use console.log to print "Hello World" on the console. Feel free to try other things as well. + +## πŸ’‘ Hint: + +5 minutes video about the console: +https://www.youtube.com/watch?v=1RlkftxAo-M \ No newline at end of file diff --git a/exercises/02-hello-world/test.py b/exercises/01-Console/app.py similarity index 100% rename from exercises/02-hello-world/test.py rename to exercises/01-Console/app.py diff --git a/exercises/01-Console/test.py b/exercises/01-Console/test.py new file mode 100644 index 00000000..e69de29b 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/26-hello-world/test.py b/exercises/26-hello-world/test.py new file mode 100644 index 00000000..4f94ffb0 --- /dev/null +++ b/exercises/26-hello-world/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From f3e1eda16cb4d0363a2cdfd83083c603313a9568 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 18 Sep 2019 14:28:34 +0000 Subject: [PATCH 02/87] initialized exercise 02 --- exercises/01-Console/app.py | 20 -------------------- exercises/01-Console/test.py | 21 +++++++++++++++++++++ exercises/02-Declare-Variables/README.md | 15 +++++++++++++++ exercises/02-Declare-Variables/app.py | 1 + exercises/02-Declare-Variables/test.py | 21 +++++++++++++++++++++ 5 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 exercises/02-Declare-Variables/README.md create mode 100644 exercises/02-Declare-Variables/app.py create mode 100644 exercises/02-Declare-Variables/test.py diff --git a/exercises/01-Console/app.py b/exercises/01-Console/app.py index 4f94ffb0..8b137891 100644 --- a/exercises/01-Console/app.py +++ b/exercises/01-Console/app.py @@ -1,21 +1 @@ -import io -import sys -sys.stdout = buffer = io.StringIO() -from app import my_function -import pytest - -@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('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 diff --git a/exercises/01-Console/test.py b/exercises/01-Console/test.py index e69de29b..ec1c2820 100644 --- a/exercises/01-Console/test.py +++ b/exercises/01-Console/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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-Declare-Variables/README.md b/exercises/02-Declare-Variables/README.md new file mode 100644 index 00000000..126f68b8 --- /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: +```js +var 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..8b137891 --- /dev/null +++ b/exercises/02-Declare-Variables/app.py @@ -0,0 +1 @@ + diff --git a/exercises/02-Declare-Variables/test.py b/exercises/02-Declare-Variables/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/02-Declare-Variables/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From aa0b2230e1ffefed0e80dead6e3f407195524629 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 18 Sep 2019 14:30:47 +0000 Subject: [PATCH 03/87] initialized exercise 03 --- .../README.md | 13 ++++++++++++ .../03-Print-Variables-In-The-Console/app.py | 1 + .../03-Print-Variables-In-The-Console/test.py | 21 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 exercises/03-Print-Variables-In-The-Console/README.md create mode 100644 exercises/03-Print-Variables-In-The-Console/app.py create mode 100644 exercises/03-Print-Variables-In-The-Console/test.py 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..b76bb1a1 --- /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 console.log function to print variables in the console, it's a great way to know their content, like this: +```js +var mySuperVariable = 'hello'; +console.log(mySuperVariable); +``` + +## πŸ“ 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..8b137891 --- /dev/null +++ b/exercises/03-Print-Variables-In-The-Console/app.py @@ -0,0 +1 @@ + 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..ec1c2820 --- /dev/null +++ b/exercises/03-Print-Variables-In-The-Console/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From cba4e2569606b73ae2224214ec370ef18dd77428 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 18 Sep 2019 14:31:54 +0000 Subject: [PATCH 04/87] initialized exercise 04 --- exercises/04-Multiply-Two-Values/README.md | 16 ++++++++++++++++ exercises/04-Multiply-Two-Values/app.py | 1 + exercises/04-Multiply-Two-Values/test.py | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 exercises/04-Multiply-Two-Values/README.md create mode 100644 exercises/04-Multiply-Two-Values/app.py create mode 100644 exercises/04-Multiply-Two-Values/test.py diff --git a/exercises/04-Multiply-Two-Values/README.md b/exercises/04-Multiply-Two-Values/README.md new file mode 100644 index 00000000..9fdb3172 --- /dev/null +++ b/exercises/04-Multiply-Two-Values/README.md @@ -0,0 +1,16 @@ +# `04` Multiply Two Values + +Any programming language lets you do basic Math operations like multiplication, division, etc. + +To multiply 2 values in javascript, you have to use the asterisk operator like this: +```js +var resultingValue = 2 * 3; +``` +In this case, we stored the result value of the multiplication into a variable called **resultingValue**. +## πŸ“ Instructions: + +1. Please store the result of multiplying 2345 times 7323 in a variable called **variablesAreCool** and the 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..8b137891 --- /dev/null +++ b/exercises/04-Multiply-Two-Values/app.py @@ -0,0 +1 @@ + diff --git a/exercises/04-Multiply-Two-Values/test.py b/exercises/04-Multiply-Two-Values/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/04-Multiply-Two-Values/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 4ca3ef5df65be19056f401beddc7f50141c4c3bf Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 18 Sep 2019 14:33:26 +0000 Subject: [PATCH 05/87] initialized exercise 05 --- exercises/05-User-Inputed-Values/README.md | 12 ++++++++++++ exercises/05-User-Inputed-Values/app.py | 1 + exercises/05-User-Inputed-Values/test.py | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 exercises/05-User-Inputed-Values/README.md create mode 100644 exercises/05-User-Inputed-Values/app.py create mode 100644 exercises/05-User-Inputed-Values/test.py diff --git a/exercises/05-User-Inputed-Values/README.md b/exercises/05-User-Inputed-Values/README.md new file mode 100644 index 00000000..d8037f8c --- /dev/null +++ b/exercises/05-User-Inputed-Values/README.md @@ -0,0 +1,12 @@ +# `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..20751a76 --- /dev/null +++ b/exercises/05-User-Inputed-Values/app.py @@ -0,0 +1 @@ +age = input('What is your age?') \ No newline at end of file diff --git a/exercises/05-User-Inputed-Values/test.py b/exercises/05-User-Inputed-Values/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/05-User-Inputed-Values/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 666c6ce126bd20172d481d9a031fdbe0f103c43a Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 18 Sep 2019 14:34:38 +0000 Subject: [PATCH 06/87] initialized exercise 06 --- exercises/06-Constants/README.md | 21 +++++++++++++++++++++ exercises/06-Constants/app.py | 0 exercises/06-Constants/test.py | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 exercises/06-Constants/README.md create mode 100644 exercises/06-Constants/app.py create mode 100644 exercises/06-Constants/test.py diff --git a/exercises/06-Constants/README.md b/exercises/06-Constants/README.md new file mode 100644 index 00000000..130357ad --- /dev/null +++ b/exercises/06-Constants/README.md @@ -0,0 +1,21 @@ +# `06` Constants + +Since 2015, Javascript also allows the usage of constants, they differ from variables because once declared, they cannot change their value over time like variables can. + +To declare a constant, you have to use the reserved word **const** instead of **var**, like this: + +```Javascript +const VERSION = '1.2'; +``` + +Constants are super useful because some times, as a developer, you want to make sure parts of your data are read-only. + + +## πŸ“ Instructions: + +1. Run the exercise and fix the error that will show on the console. +2. Make the code output **0.9** on the console when fixed. + +## πŸ’‘ Hint: + +Search the error on google.com to learn how to fix it. \ No newline at end of file diff --git a/exercises/06-Constants/app.py b/exercises/06-Constants/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/06-Constants/test.py b/exercises/06-Constants/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/06-Constants/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From cccf6898485489ccc38345a8ee0667938dd58f61 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 18 Sep 2019 14:36:11 +0000 Subject: [PATCH 07/87] initialized exercise 07 --- exercises/07-String-Concatenation/README.md | 24 +++++++++++++++++++++ exercises/07-String-Concatenation/app.py | 8 +++++++ exercises/07-String-Concatenation/test.py | 21 ++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 exercises/07-String-Concatenation/README.md create mode 100644 exercises/07-String-Concatenation/app.py create mode 100644 exercises/07-String-Concatenation/test.py diff --git a/exercises/07-String-Concatenation/README.md b/exercises/07-String-Concatenation/README.md new file mode 100644 index 00000000..ddcbf2ff --- /dev/null +++ b/exercises/07-String-Concatenation/README.md @@ -0,0 +1,24 @@ +# `07` String Concatenation + +One of Javascript's main objectives is to generate HTML code; concatenation comes in handy +because you can create and add to existing HTML strings. To concatenate strings, we use +the + (plus) operator, for example: + +```Javascript +var one = 'a'; +var two = 'b'; +console.log(one+two); //this will print 'ab' on the console. +``` + +Constants are super useful because some times, as a developer, you want to make sure parts of your data are read-only. + + +## πŸ“ Instructions: + +1. Set the values for myVar1 and myVar2 so the code prints 'Hello World' in the console. + + +## πŸ’‘ Hint: + +Here is a 2min video explaining how to concatenate strings and what are they useful for. +https://www.youtube.com/watch?v=cExgK0AnCdM diff --git a/exercises/07-String-Concatenation/app.py b/exercises/07-String-Concatenation/app.py new file mode 100644 index 00000000..bb20a140 --- /dev/null +++ b/exercises/07-String-Concatenation/app.py @@ -0,0 +1,8 @@ +//Set the values here + + + + +//Don't change any of this line +var theNewString = myVar1+' '+myVar2 +console.log(theNewString) \ No newline at end of file diff --git a/exercises/07-String-Concatenation/test.py b/exercises/07-String-Concatenation/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/07-String-Concatenation/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 4806ba1f0d48ef2fa6431b944c8a4307b9168f13 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 18 Sep 2019 14:38:43 +0000 Subject: [PATCH 08/87] initialized exercise 08 --- exercises/08-Create-a-Basic-HTML/README.md | 23 ++++++++++++++++++++++ exercises/08-Create-a-Basic-HTML/app.py | 10 ++++++++++ exercises/08-Create-a-Basic-HTML/test.py | 21 ++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 exercises/08-Create-a-Basic-HTML/README.md create mode 100644 exercises/08-Create-a-Basic-HTML/app.py create mode 100644 exercises/08-Create-a-Basic-HTML/test.py diff --git a/exercises/08-Create-a-Basic-HTML/README.md b/exercises/08-Create-a-Basic-HTML/README.md new file mode 100644 index 00000000..a12b41d5 --- /dev/null +++ b/exercises/08-Create-a-Basic-HTML/README.md @@ -0,0 +1,23 @@ +# `08` Create a basic HTML + +Let's continue using string concatenation to generate HTML... + + + + +## πŸ“ Instructions: + +1. The code on the left contains 8 constants with different string values, please use +the constants and concatenate them together to set the value of the variable **htmlDocument** +a new string that has the content of a typical HTML document (with the HTML tags in the +right order). + +Then, print the value of htmlDocument on the console. + +The output should look like this: + +```js + + +``` + diff --git a/exercises/08-Create-a-Basic-HTML/app.py b/exercises/08-Create-a-Basic-HTML/app.py new file mode 100644 index 00000000..508e08cb --- /dev/null +++ b/exercises/08-Create-a-Basic-HTML/app.py @@ -0,0 +1,10 @@ + a = '' + b = '' + c = '' + d = '' + e = '' + f = '' + g = '' + h = '<body>' + +# DON'T CHANGE THE CODE ABOVE \ No newline at end of file diff --git a/exercises/08-Create-a-Basic-HTML/test.py b/exercises/08-Create-a-Basic-HTML/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/08-Create-a-Basic-HTML/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From dde938af64f28452d28acd895871cb5b2ae097ee Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:39:49 +0000 Subject: [PATCH 09/87] initialized exercise 09 --- .../09-Calling-Your-First-Function/README.md | 17 +++++++++++++++ .../09-Calling-Your-First-Function/app.py | 6 ++++++ .../09-Calling-Your-First-Function/test.py | 21 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 exercises/09-Calling-Your-First-Function/README.md create mode 100644 exercises/09-Calling-Your-First-Function/app.py create mode 100644 exercises/09-Calling-Your-First-Function/test.py diff --git a/exercises/09-Calling-Your-First-Function/README.md b/exercises/09-Calling-Your-First-Function/README.md new file mode 100644 index 00000000..e8adf395 --- /dev/null +++ b/exercises/09-Calling-Your-First-Function/README.md @@ -0,0 +1,17 @@ +# `09` 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 isOdd 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/09-Calling-Your-First-Function/app.py b/exercises/09-Calling-Your-First-Function/app.py new file mode 100644 index 00000000..450b6d9d --- /dev/null +++ b/exercises/09-Calling-Your-First-Function/app.py @@ -0,0 +1,6 @@ +function isOdd(myNumber) +{ + return !(myNumber % 2 == 0); +} + +//your code here \ No newline at end of file diff --git a/exercises/09-Calling-Your-First-Function/test.py b/exercises/09-Calling-Your-First-Function/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/09-Calling-Your-First-Function/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 76b27dcd9e6ac06472912f93565f4b168fea6d26 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:40:52 +0000 Subject: [PATCH 10/87] initialized exercise 10 --- .../10-Creating-Your-First-Function/README.md | 22 +++++++++++++++++++ .../10-Creating-Your-First-Function/app.py | 7 ++++++ .../10-Creating-Your-First-Function/test.py | 21 ++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 exercises/10-Creating-Your-First-Function/README.md create mode 100644 exercises/10-Creating-Your-First-Function/app.py create mode 100644 exercises/10-Creating-Your-First-Function/test.py diff --git a/exercises/10-Creating-Your-First-Function/README.md b/exercises/10-Creating-Your-First-Function/README.md new file mode 100644 index 00000000..c9908bb0 --- /dev/null +++ b/exercises/10-Creating-Your-First-Function/README.md @@ -0,0 +1,22 @@ +# `10` Creating Your First Function + + +## πŸ“ Instructions: + +1. The function addNumbers 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 **"addNumbers"** 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/10-Creating-Your-First-Function/app.py b/exercises/10-Creating-Your-First-Function/app.py new file mode 100644 index 00000000..d8cbe18e --- /dev/null +++ b/exercises/10-Creating-Your-First-Function/app.py @@ -0,0 +1,7 @@ +function addNumbers(a,b) +{ + //your code here + +} + +console.log(addNumbers(3,4)) \ No newline at end of file diff --git a/exercises/10-Creating-Your-First-Function/test.py b/exercises/10-Creating-Your-First-Function/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/10-Creating-Your-First-Function/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From d772cfe7454bdf0bc143b0fd07fa415d5d167907 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:41:54 +0000 Subject: [PATCH 11/87] initialized exercise 11 --- exercises/11-Create-A-New-Function/README.md | 32 ++++++++++++++++++++ exercises/11-Create-A-New-Function/app.py | 1 + exercises/11-Create-A-New-Function/test.py | 21 +++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 exercises/11-Create-A-New-Function/README.md create mode 100644 exercises/11-Create-A-New-Function/app.py create mode 100644 exercises/11-Create-A-New-Function/test.py diff --git a/exercises/11-Create-A-New-Function/README.md b/exercises/11-Create-A-New-Function/README.md new file mode 100644 index 00000000..5370ac63 --- /dev/null +++ b/exercises/11-Create-A-New-Function/README.md @@ -0,0 +1,32 @@ +# `11` 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: + +```js +function addNumbers(a, b){ + return a + b; +} + +``` + +But Javascript comes with a bunch of "pre defined" functions that you can use, for example: + +```js +Math.random(); +} + +``` + +You can use the Math.random() function to get a random decimal number between 0 and 1, every +time you call that function it will return another random decimal number between 0 and 1. + +## πŸ“ Instructions: + +1. Please now create a function called **generateRandom** that generates a random number +between 0 and 9 every time it is called. + +## πŸ’‘ Hint: + +One possible solution involves using two predefined functions: the **Math.random** and **Math.floor** functions. + diff --git a/exercises/11-Create-A-New-Function/app.py b/exercises/11-Create-A-New-Function/app.py new file mode 100644 index 00000000..5214438f --- /dev/null +++ b/exercises/11-Create-A-New-Function/app.py @@ -0,0 +1 @@ +# declare your function here \ No newline at end of file diff --git a/exercises/11-Create-A-New-Function/test.py b/exercises/11-Create-A-New-Function/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/11-Create-A-New-Function/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 7d3f565283c4919f79f2e4a32974fd4b1af1ec11 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:42:58 +0000 Subject: [PATCH 12/87] initialized exercise 12 --- exercises/12-Your-First-If/README.md | 17 +++++++++++++++++ exercises/12-Your-First-If/app.py | 3 +++ exercises/12-Your-First-If/test.py | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 exercises/12-Your-First-If/README.md create mode 100644 exercises/12-Your-First-If/app.py create mode 100644 exercises/12-Your-First-If/test.py diff --git a/exercises/12-Your-First-If/README.md b/exercises/12-Your-First-If/README.md new file mode 100644 index 00000000..4a0c856a --- /dev/null +++ b/exercises/12-Your-First-If/README.md @@ -0,0 +1,17 @@ +# `12` Your First if... + +The current application is prompting asking how much money the user has. Once the user inputs +the amount, we need to **console.log** 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. + diff --git a/exercises/12-Your-First-If/app.py b/exercises/12-Your-First-If/app.py new file mode 100644 index 00000000..4933562f --- /dev/null +++ b/exercises/12-Your-First-If/app.py @@ -0,0 +1,3 @@ +var total = prompt('How much money do you have in your pocket'); + +#your code here \ No newline at end of file diff --git a/exercises/12-Your-First-If/test.py b/exercises/12-Your-First-If/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/12-Your-First-If/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 8764cbb8f0399e1e5d5919134a7405a518ef6fc3 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:44:05 +0000 Subject: [PATCH 13/87] initialized exercise 13 --- .../13-How-Much-The-Wedding-Costs/README.md | 21 +++++++++++++++++++ .../13-How-Much-The-Wedding-Costs/app.py | 3 +++ .../13-How-Much-The-Wedding-Costs/test.py | 21 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 exercises/13-How-Much-The-Wedding-Costs/README.md create mode 100644 exercises/13-How-Much-The-Wedding-Costs/app.py create mode 100644 exercises/13-How-Much-The-Wedding-Costs/test.py diff --git a/exercises/13-How-Much-The-Wedding-Costs/README.md b/exercises/13-How-Much-The-Wedding-Costs/README.md new file mode 100644 index 00000000..fba41854 --- /dev/null +++ b/exercises/13-How-Much-The-Wedding-Costs/README.md @@ -0,0 +1,21 @@ +# `13` 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/13-How-Much-The-Wedding-Costs/app.py b/exercises/13-How-Much-The-Wedding-Costs/app.py new file mode 100644 index 00000000..bbf06b72 --- /dev/null +++ b/exercises/13-How-Much-The-Wedding-Costs/app.py @@ -0,0 +1,3 @@ +userInput = prompt('How many people are coming to your wedding?'); + +# your code here \ No newline at end of file diff --git a/exercises/13-How-Much-The-Wedding-Costs/test.py b/exercises/13-How-Much-The-Wedding-Costs/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/13-How-Much-The-Wedding-Costs/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 271cca9cdbb170107cf11bf43790e64e1050cdf5 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:45:22 +0000 Subject: [PATCH 14/87] initialized exercise 14 --- exercises/14-Your-First-Switch/README.md | 16 ++++++++++++++++ exercises/14-Your-First-Switch/app.py | 14 ++++++++++++++ exercises/14-Your-First-Switch/test.py | 21 +++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 exercises/14-Your-First-Switch/README.md create mode 100644 exercises/14-Your-First-Switch/app.py create mode 100644 exercises/14-Your-First-Switch/test.py diff --git a/exercises/14-Your-First-Switch/README.md b/exercises/14-Your-First-Switch/README.md new file mode 100644 index 00000000..c54fa40f --- /dev/null +++ b/exercises/14-Your-First-Switch/README.md @@ -0,0 +1,16 @@ +# `14` Your First Switch + +Imagine your software is running the inventory of a shoe store, a client needs to know in +what colors do you have a particular shoe. + + + +## πŸ“ Instructions: + +1. Complete this switch statement with 3 possible colors: Red, Green and Blue. + +The function needs to return **true** if the color is available or **false** if the color is not available. + +## πŸ’‘ Hint: + +http://www.w3schools.com/js/js_switch.asp \ No newline at end of file diff --git a/exercises/14-Your-First-Switch/app.py b/exercises/14-Your-First-Switch/app.py new file mode 100644 index 00000000..4f42eeb0 --- /dev/null +++ b/exercises/14-Your-First-Switch/app.py @@ -0,0 +1,14 @@ +function getColor(selection) +{ + switch(selection){ + //Add more options here + default : + return false;//return false because the user pick a unavailable color + break; + } +} + +var colorname = window.prompt('What color do you want?'); +var isAvailable = getColor(colorname); +if(isAvailable) console.log('Good news! That color is available'); +else console.log('We are sorry, that color is not available'); \ No newline at end of file diff --git a/exercises/14-Your-First-Switch/test.py b/exercises/14-Your-First-Switch/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/14-Your-First-Switch/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 88563543522eced3aa01a51fd3feb2f7f39a477c Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:56:09 +0000 Subject: [PATCH 15/87] initialized exercise 15 --- exercises/15-Random-Numbers/README.md | 14 ++++++++++++++ exercises/15-Random-Numbers/app.py | 8 ++++++++ exercises/15-Random-Numbers/test.py | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 exercises/15-Random-Numbers/README.md create mode 100644 exercises/15-Random-Numbers/app.py create mode 100644 exercises/15-Random-Numbers/test.py diff --git a/exercises/15-Random-Numbers/README.md b/exercises/15-Random-Numbers/README.md new file mode 100644 index 00000000..2016ed66 --- /dev/null +++ b/exercises/15-Random-Numbers/README.md @@ -0,0 +1,14 @@ +# `15` Random Numbers + +The **Math.random()** function will return a random decimal number between 0 and 1, run the exercise as it is several times to test it. + +## πŸ“ Instructions: + +1. Now, please update the function code to make it return an integer (no decimals) number between 1 and 10. + +## πŸ’‘ Hint: + +- Math.random only returns decimal numbers from 0 to 1, and we need Integer numbers from 1 to 10. +- Multiply the Math.random() by 10 to move the decimal 2 slots to the right. +- Use the Math.floor() function to remove the rest of the decimals and have only integers. + diff --git a/exercises/15-Random-Numbers/app.py b/exercises/15-Random-Numbers/app.py new file mode 100644 index 00000000..64c42868 --- /dev/null +++ b/exercises/15-Random-Numbers/app.py @@ -0,0 +1,8 @@ +function getRandomInt() +{ + var randomNumber = Math.floor(Math.random() * 10)+ 1; + return randomNumber; +} + + +console.log(getRandomInt()) \ No newline at end of file diff --git a/exercises/15-Random-Numbers/test.py b/exercises/15-Random-Numbers/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/15-Random-Numbers/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 1eb01f568c4753187666e49c3705376b786b7988 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:57:21 +0000 Subject: [PATCH 16/87] initialized exercise 16 --- exercises/16-Rand-From-One-to-Six/README.md | 13 +++++++++++++ exercises/16-Rand-From-One-to-Six/app.py | 0 exercises/16-Rand-From-One-to-Six/test.py | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 exercises/16-Rand-From-One-to-Six/README.md create mode 100644 exercises/16-Rand-From-One-to-Six/app.py create mode 100644 exercises/16-Rand-From-One-to-Six/test.py diff --git a/exercises/16-Rand-From-One-to-Six/README.md b/exercises/16-Rand-From-One-to-Six/README.md new file mode 100644 index 00000000..e23f32d6 --- /dev/null +++ b/exercises/16-Rand-From-One-to-Six/README.md @@ -0,0 +1,13 @@ +# `16` Rand From 1 to 6 + + +## πŸ“ Instructions: + +1. Okay, now change whatever you need to change to make the algorithm print random integers between 1 and 6. + +## πŸ’‘ Hint: + +- It should print between 1 and 6, not between 0 and 6. +- This exercise is super simple, don't over complicate things.... + + diff --git a/exercises/16-Rand-From-One-to-Six/app.py b/exercises/16-Rand-From-One-to-Six/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/16-Rand-From-One-to-Six/test.py b/exercises/16-Rand-From-One-to-Six/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/16-Rand-From-One-to-Six/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 7244acd38786455f3ac939516c598035cc71bef1 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:58:16 +0000 Subject: [PATCH 17/87] initialized exercise 17 --- exercises/17-Your-First-Loop/README.md | 7 +++++++ exercises/17-Your-First-Loop/app.py | 0 exercises/17-Your-First-Loop/test.py | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 exercises/17-Your-First-Loop/README.md create mode 100644 exercises/17-Your-First-Loop/app.py create mode 100644 exercises/17-Your-First-Loop/test.py diff --git a/exercises/17-Your-First-Loop/README.md b/exercises/17-Your-First-Loop/README.md new file mode 100644 index 00000000..818f301f --- /dev/null +++ b/exercises/17-Your-First-Loop/README.md @@ -0,0 +1,7 @@ +# `17` 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/17-Your-First-Loop/app.py b/exercises/17-Your-First-Loop/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/17-Your-First-Loop/test.py b/exercises/17-Your-First-Loop/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/17-Your-First-Loop/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 70bada7d5df92ec0691f41e57b8420d17f4882df Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 14:59:18 +0000 Subject: [PATCH 18/87] initialized exercise 18 --- exercises/18-Create-A-For-Loop/README.md | 14 ++++++++++++++ exercises/18-Create-A-For-Loop/app.py | 0 exercises/18-Create-A-For-Loop/test.py | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 exercises/18-Create-A-For-Loop/README.md create mode 100644 exercises/18-Create-A-For-Loop/app.py create mode 100644 exercises/18-Create-A-For-Loop/test.py diff --git a/exercises/18-Create-A-For-Loop/README.md b/exercises/18-Create-A-For-Loop/README.md new file mode 100644 index 00000000..319f41f1 --- /dev/null +++ b/exercises/18-Create-A-For-Loop/README.md @@ -0,0 +1,14 @@ +# `18` 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/js/js_loop_for.asp +``` + +## πŸ“ Instructions: + +1. Create a function called **standardsMaker** that prints 300 times the phrase "I will write questions if I'm stuck". diff --git a/exercises/18-Create-A-For-Loop/app.py b/exercises/18-Create-A-For-Loop/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/18-Create-A-For-Loop/test.py b/exercises/18-Create-A-For-Loop/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/18-Create-A-For-Loop/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 1502e98cc53f4b3d60a27a72bf4e560d538ed12c Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:00:08 +0000 Subject: [PATCH 19/87] initialized exercise 19 --- exercises/19-While-Loop/README.md | 7 +++++++ exercises/19-While-Loop/app.py | 0 exercises/19-While-Loop/test.py | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 exercises/19-While-Loop/README.md create mode 100644 exercises/19-While-Loop/app.py create mode 100644 exercises/19-While-Loop/test.py diff --git a/exercises/19-While-Loop/README.md b/exercises/19-While-Loop/README.md new file mode 100644 index 00000000..56dd9720 --- /dev/null +++ b/exercises/19-While-Loop/README.md @@ -0,0 +1,7 @@ +# `19` 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. + +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/19-While-Loop/app.py b/exercises/19-While-Loop/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/19-While-Loop/test.py b/exercises/19-While-Loop/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/19-While-Loop/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From cd664d4539f2db40683d9ba72cc93c9416eab043 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:00:58 +0000 Subject: [PATCH 20/87] initialized exercise 20 --- exercises/20-Random-Colors-Loop/README.md | 25 +++++++++++++++++++++++ exercises/20-Random-Colors-Loop/app.py | 0 exercises/20-Random-Colors-Loop/test.py | 21 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 exercises/20-Random-Colors-Loop/README.md create mode 100644 exercises/20-Random-Colors-Loop/app.py create mode 100644 exercises/20-Random-Colors-Loop/test.py diff --git a/exercises/20-Random-Colors-Loop/README.md b/exercises/20-Random-Colors-Loop/README.md new file mode 100644 index 00000000..a46a2d15 --- /dev/null +++ b/exercises/20-Random-Colors-Loop/README.md @@ -0,0 +1,25 @@ +# `20` 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 "**getAllStudentColors**" 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 **Math.random()** function we saw on the last exercise. +- Use the "**getColor**" function on this exercise to get the color name from the number you get. +- Print the color on the console. + +## IMPORTANT MESSAGE: + +If you feel you are not understanding looping, its a good idea to complete the Arrays Exercises classroom and then come back here: +```sh +https://repl.it/classroom/invite/BB4WDpk +``` \ No newline at end of file diff --git a/exercises/20-Random-Colors-Loop/app.py b/exercises/20-Random-Colors-Loop/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/20-Random-Colors-Loop/test.py b/exercises/20-Random-Colors-Loop/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/20-Random-Colors-Loop/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From e843f35b22cb9beafef84fee803760d7117a0891 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:02:06 +0000 Subject: [PATCH 21/87] initialized exercise 21 --- exercises/21-Looping-With-FizzBuzz/README.md | 44 ++++++++++++++++++++ exercises/21-Looping-With-FizzBuzz/app.py | 0 exercises/21-Looping-With-FizzBuzz/test.py | 21 ++++++++++ 3 files changed, 65 insertions(+) create mode 100644 exercises/21-Looping-With-FizzBuzz/README.md create mode 100644 exercises/21-Looping-With-FizzBuzz/app.py create mode 100644 exercises/21-Looping-With-FizzBuzz/test.py diff --git a/exercises/21-Looping-With-FizzBuzz/README.md b/exercises/21-Looping-With-FizzBuzz/README.md new file mode 100644 index 00000000..7b784c1f --- /dev/null +++ b/exercises/21-Looping-With-FizzBuzz/README.md @@ -0,0 +1,44 @@ +# `21` 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: + +```js +/* output +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/21-Looping-With-FizzBuzz/app.py b/exercises/21-Looping-With-FizzBuzz/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/21-Looping-With-FizzBuzz/test.py b/exercises/21-Looping-With-FizzBuzz/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/21-Looping-With-FizzBuzz/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From ab4ddd5fa2af2c610111b5967b7e576d0361a0a3 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:02:55 +0000 Subject: [PATCH 22/87] initialized exercise 22 --- exercises/22-Russian-Roulette/README.md | 19 +++++++++++++++++++ exercises/22-Russian-Roulette/app.py | 0 exercises/22-Russian-Roulette/test.py | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 exercises/22-Russian-Roulette/README.md create mode 100644 exercises/22-Russian-Roulette/app.py create mode 100644 exercises/22-Russian-Roulette/test.py diff --git a/exercises/22-Russian-Roulette/README.md b/exercises/22-Russian-Roulette/README.md new file mode 100644 index 00000000..9033fe26 --- /dev/null +++ b/exercises/22-Russian-Roulette/README.md @@ -0,0 +1,19 @@ +# `22` 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 "**fireGun**" to make the game work +(compare the bullet position against the chamber position.) + + +## πŸ’‘ Hint: + +- The function needs to return **true** or **false** depending on the result, if the bullet was +at the same slot as the revolver chamber, then it will be fired (**false**). diff --git a/exercises/22-Russian-Roulette/app.py b/exercises/22-Russian-Roulette/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/22-Russian-Roulette/test.py b/exercises/22-Russian-Roulette/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/22-Russian-Roulette/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From a0593066df92b931936fcd5a90cbfc885fc3339d Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:03:34 +0000 Subject: [PATCH 23/87] initialized exercise 23 --- exercises/23-The-Beatles/README.md | 21 +++++++++++++++++++++ exercises/23-The-Beatles/app.py | 0 exercises/23-The-Beatles/test.py | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 exercises/23-The-Beatles/README.md create mode 100644 exercises/23-The-Beatles/app.py create mode 100644 exercises/23-The-Beatles/test.py diff --git a/exercises/23-The-Beatles/README.md b/exercises/23-The-Beatles/README.md new file mode 100644 index 00000000..8aa7eb50 --- /dev/null +++ b/exercises/23-The-Beatles/README.md @@ -0,0 +1,21 @@ +# `23` 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 and function called **sing** that 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: + +let it be, let it be, let it be, let it be, 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/23-The-Beatles/app.py b/exercises/23-The-Beatles/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/23-The-Beatles/test.py b/exercises/23-The-Beatles/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/23-The-Beatles/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 63dc9ae93384d0e8e496a201b99c626128fec5a7 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:04:18 +0000 Subject: [PATCH 24/87] initialized exercise 24 --- exercises/24-Bottles-Of-Milk/README.md | 33 ++++++++++++++++++++++++++ exercises/24-Bottles-Of-Milk/app.py | 0 exercises/24-Bottles-Of-Milk/test.py | 21 ++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 exercises/24-Bottles-Of-Milk/README.md create mode 100644 exercises/24-Bottles-Of-Milk/app.py create mode 100644 exercises/24-Bottles-Of-Milk/test.py diff --git a/exercises/24-Bottles-Of-Milk/README.md b/exercises/24-Bottles-Of-Milk/README.md new file mode 100644 index 00000000..3ff8c5b8 --- /dev/null +++ b/exercises/24-Bottles-Of-Milk/README.md @@ -0,0 +1,33 @@ +# `24` 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 write an algorithm to print the exact same lyrics. + +let it be, let it be, let it be, let it be, 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: + +- 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/24-Bottles-Of-Milk/app.py b/exercises/24-Bottles-Of-Milk/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/24-Bottles-Of-Milk/test.py b/exercises/24-Bottles-Of-Milk/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/24-Bottles-Of-Milk/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 3c319f32a6c2a61992723d0967fcd0541dff3f1d Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:10:35 +0000 Subject: [PATCH 25/87] initialized exercise 25 --- exercises/25-Python-Objects/README.md | 93 +++++++++++++++++++++++++++ exercises/25-Python-Objects/app.py | 0 exercises/25-Python-Objects/test.py | 21 ++++++ 3 files changed, 114 insertions(+) create mode 100644 exercises/25-Python-Objects/README.md create mode 100644 exercises/25-Python-Objects/app.py create mode 100644 exercises/25-Python-Objects/test.py diff --git a/exercises/25-Python-Objects/README.md b/exercises/25-Python-Objects/README.md new file mode 100644 index 00000000..59d735df --- /dev/null +++ b/exercises/25-Python-Objects/README.md @@ -0,0 +1,93 @@ +# `25` Javascript 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: + +```Javascript +var car1Model = "corolla"; +var car1Make = "Toyota"; +var car1Color = "green"; +var car1Year = 2015; + +var car2Model = "santa fe"; +var car2Make = "Hyundai"; +var car2Color = "purple"; +var car2Year = 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: + +```js +var car1 = { model: "corolla", make: "toyota", color: "green", year: 2015}; + +``` + +You can see the key: value separated by a comma. + +And for us (developers) to read it easier we write it like this: + +```js +var car1 = { + model: "corolla", + make: "toyota", + color: "green", + 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: + +```js + +var person = { + name: "John", //String + lastname: "Doe", + age: 35, //Number + gender: "male", + lucky_numbers: [ 7, 11, 13, 17], //Array + significant_other: person2 //Object, yes the same variable/object defined after +}; + +var person2 = { + name: "Jane", + lastname: "Doe", + age: 38, + gender: "female", + lucky_numbers: [ 2, 4, 6, 8], + significant_other: person +}; + +var family = { + lastname: "Doe", + 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: + +```js +console.log(family.members[0].name); +``` + +Or the 3rd lucky number of the significant other of the second member of Doe's family: + +```Javascript +console.log( family.members[1].significant_other.lucky_numbers[2]); +``` + +Easy stuff :) +## πŸ“ Instructions: +1. Programmatically, change the fourth lucky number of John Doe to 33 (use a command, don't manually change the code) +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. Now please print ( console.log() ) the SUM of all of the lucky numbers of the Doe family. + +## πŸ’‘ Hint: + +- You can get each array of lucky numbers from each person object inside the family object. +- Once you get each array just loop over it adding every element (like we've been doing so far). And then add each sum of the 3 family members. +- Null is also an object. diff --git a/exercises/25-Python-Objects/app.py b/exercises/25-Python-Objects/app.py new file mode 100644 index 00000000..e69de29b diff --git a/exercises/25-Python-Objects/test.py b/exercises/25-Python-Objects/test.py new file mode 100644 index 00000000..ec1c2820 --- /dev/null +++ b/exercises/25-Python-Objects/test.py @@ -0,0 +1,21 @@ +import io +import sys +sys.stdout = buffer = io.StringIO() + +from app import my_function +import pytest + +@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('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 From 04db4e32c9e0a49b1ef58976020ee4e6c38dec7d Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:12:35 +0000 Subject: [PATCH 26/87] updated README 01 for Python --- exercises/01-Console/README.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/exercises/01-Console/README.md b/exercises/01-Console/README.md index eacb806d..9bddfc8c 100644 --- a/exercises/01-Console/README.md +++ b/exercises/01-Console/README.md @@ -1,19 +1,16 @@ # `01` Console -In JavaScript, we use console.log to make the computer write anything we want (the content of a variable, a given string, etc.) in something called "the 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. +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: -```js -console.log("How are you?"); +```py +print("How are you?") ``` ## πŸ“ Instructions: -Use console.log to print "Hello World" on the console. Feel free to try other things as well. +Use **print**** to print "Hello World" on the console. Feel free to try other things as well. -## πŸ’‘ Hint: - -5 minutes video about the console: -https://www.youtube.com/watch?v=1RlkftxAo-M \ No newline at end of file From 7830642d846b7b6c144ee4d8916a8f5ee570967b Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:14:13 +0000 Subject: [PATCH 27/87] updated README 02 for Python --- exercises/02-Declare-Variables/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/02-Declare-Variables/README.md b/exercises/02-Declare-Variables/README.md index 126f68b8..4a4948ed 100644 --- a/exercises/02-Declare-Variables/README.md +++ b/exercises/02-Declare-Variables/README.md @@ -1,8 +1,8 @@ # `02` Declare Variables Variables act as a box (container) that lets you store different types of data. This is how we set a variable: -```js -var name = "Daniel"; +```py +name = "Daniel" ``` ## πŸ“ Instructions: From 96c1a7f6700102053a18bdc952e30c6c2aff49a7 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 15:27:00 +0000 Subject: [PATCH 28/87] fixed issues --- exercises/01-Console/test.py | 18 +++++++++--------- exercises/02-Declare-Variables/test.py | 18 +++++++++--------- .../README.md | 8 ++++---- .../03-Print-Variables-In-The-Console/test.py | 18 +++++++++--------- exercises/04-Multiply-Two-Values/README.md | 11 ++++++----- exercises/04-Multiply-Two-Values/test.py | 18 +++++++++--------- exercises/05-User-Inputed-Values/app.py | 2 +- exercises/05-User-Inputed-Values/test.py | 18 +++++++++--------- exercises/06-Constants/test.py | 18 +++++++++--------- exercises/07-String-Concatenation/test.py | 18 +++++++++--------- exercises/08-Create-a-Basic-HTML/test.py | 18 +++++++++--------- .../09-Calling-Your-First-Function/test.py | 18 +++++++++--------- .../10-Creating-Your-First-Function/test.py | 18 +++++++++--------- exercises/11-Create-A-New-Function/test.py | 18 +++++++++--------- exercises/12-Your-First-If/test.py | 18 +++++++++--------- .../13-How-Much-The-Wedding-Costs/test.py | 18 +++++++++--------- exercises/14-Your-First-Switch/test.py | 18 +++++++++--------- exercises/15-Random-Numbers/test.py | 18 +++++++++--------- exercises/16-Rand-From-One-to-Six/test.py | 18 +++++++++--------- exercises/17-Your-First-Loop/test.py | 18 +++++++++--------- exercises/18-Create-A-For-Loop/test.py | 18 +++++++++--------- exercises/19-While-Loop/test.py | 18 +++++++++--------- exercises/20-Random-Colors-Loop/test.py | 18 +++++++++--------- exercises/21-Looping-With-FizzBuzz/test.py | 18 +++++++++--------- exercises/22-Russian-Roulette/test.py | 18 +++++++++--------- exercises/23-The-Beatles/test.py | 18 +++++++++--------- exercises/24-Bottles-Of-Milk/test.py | 18 +++++++++--------- exercises/25-Python-Objects/test.py | 18 +++++++++--------- 28 files changed, 236 insertions(+), 235 deletions(-) diff --git a/exercises/01-Console/test.py b/exercises/01-Console/test.py index ec1c2820..b80fb1fc 100644 --- a/exercises/01-Console/test.py +++ b/exercises/01-Console/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function + import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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-Declare-Variables/test.py b/exercises/02-Declare-Variables/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/02-Declare-Variables/test.py +++ b/exercises/02-Declare-Variables/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/03-Print-Variables-In-The-Console/README.md b/exercises/03-Print-Variables-In-The-Console/README.md index b76bb1a1..c365d25a 100644 --- a/exercises/03-Print-Variables-In-The-Console/README.md +++ b/exercises/03-Print-Variables-In-The-Console/README.md @@ -1,9 +1,9 @@ # `03` Print the Variables in the console -You can also use the console.log function to print variables in the console, it's a great way to know their content, like this: -```js -var mySuperVariable = 'hello'; -console.log(mySuperVariable); +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: diff --git a/exercises/03-Print-Variables-In-The-Console/test.py b/exercises/03-Print-Variables-In-The-Console/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/03-Print-Variables-In-The-Console/test.py +++ b/exercises/03-Print-Variables-In-The-Console/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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 index 9fdb3172..9e497129 100644 --- a/exercises/04-Multiply-Two-Values/README.md +++ b/exercises/04-Multiply-Two-Values/README.md @@ -2,14 +2,15 @@ Any programming language lets you do basic Math operations like multiplication, division, etc. -To multiply 2 values in javascript, you have to use the asterisk operator like this: -```js -var resultingValue = 2 * 3; +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 **resultingValue**. +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 **variablesAreCool** and the print the result in the console. +1. Please store the result of multiplying 2345 times 7323 in a variable called **variables_are_cool** and the print the result in the console. diff --git a/exercises/04-Multiply-Two-Values/test.py b/exercises/04-Multiply-Two-Values/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/04-Multiply-Two-Values/test.py +++ b/exercises/04-Multiply-Two-Values/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/05-User-Inputed-Values/app.py b/exercises/05-User-Inputed-Values/app.py index 20751a76..2b12f740 100644 --- a/exercises/05-User-Inputed-Values/app.py +++ b/exercises/05-User-Inputed-Values/app.py @@ -1 +1 @@ -age = input('What is your age?') \ No newline at end of file +age = int(input('What is your age?')) \ No newline at end of file diff --git a/exercises/05-User-Inputed-Values/test.py b/exercises/05-User-Inputed-Values/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/05-User-Inputed-Values/test.py +++ b/exercises/05-User-Inputed-Values/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/06-Constants/test.py b/exercises/06-Constants/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/06-Constants/test.py +++ b/exercises/06-Constants/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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-String-Concatenation/test.py b/exercises/07-String-Concatenation/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/07-String-Concatenation/test.py +++ b/exercises/07-String-Concatenation/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/08-Create-a-Basic-HTML/test.py b/exercises/08-Create-a-Basic-HTML/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/08-Create-a-Basic-HTML/test.py +++ b/exercises/08-Create-a-Basic-HTML/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/09-Calling-Your-First-Function/test.py b/exercises/09-Calling-Your-First-Function/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/09-Calling-Your-First-Function/test.py +++ b/exercises/09-Calling-Your-First-Function/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/10-Creating-Your-First-Function/test.py b/exercises/10-Creating-Your-First-Function/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/10-Creating-Your-First-Function/test.py +++ b/exercises/10-Creating-Your-First-Function/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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-Create-A-New-Function/test.py b/exercises/11-Create-A-New-Function/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/11-Create-A-New-Function/test.py +++ b/exercises/11-Create-A-New-Function/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/12-Your-First-If/test.py b/exercises/12-Your-First-If/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/12-Your-First-If/test.py +++ b/exercises/12-Your-First-If/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/13-How-Much-The-Wedding-Costs/test.py b/exercises/13-How-Much-The-Wedding-Costs/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/test.py +++ b/exercises/13-How-Much-The-Wedding-Costs/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/14-Your-First-Switch/test.py b/exercises/14-Your-First-Switch/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/14-Your-First-Switch/test.py +++ b/exercises/14-Your-First-Switch/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/15-Random-Numbers/test.py b/exercises/15-Random-Numbers/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/15-Random-Numbers/test.py +++ b/exercises/15-Random-Numbers/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/16-Rand-From-One-to-Six/test.py b/exercises/16-Rand-From-One-to-Six/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/16-Rand-From-One-to-Six/test.py +++ b/exercises/16-Rand-From-One-to-Six/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/17-Your-First-Loop/test.py b/exercises/17-Your-First-Loop/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/17-Your-First-Loop/test.py +++ b/exercises/17-Your-First-Loop/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/18-Create-A-For-Loop/test.py b/exercises/18-Create-A-For-Loop/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/18-Create-A-For-Loop/test.py +++ b/exercises/18-Create-A-For-Loop/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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-While-Loop/test.py b/exercises/19-While-Loop/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/19-While-Loop/test.py +++ b/exercises/19-While-Loop/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/20-Random-Colors-Loop/test.py b/exercises/20-Random-Colors-Loop/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/20-Random-Colors-Loop/test.py +++ b/exercises/20-Random-Colors-Loop/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/21-Looping-With-FizzBuzz/test.py b/exercises/21-Looping-With-FizzBuzz/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/21-Looping-With-FizzBuzz/test.py +++ b/exercises/21-Looping-With-FizzBuzz/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/22-Russian-Roulette/test.py b/exercises/22-Russian-Roulette/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/22-Russian-Roulette/test.py +++ b/exercises/22-Russian-Roulette/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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-The-Beatles/test.py b/exercises/23-The-Beatles/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/23-The-Beatles/test.py +++ b/exercises/23-The-Beatles/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/24-Bottles-Of-Milk/test.py b/exercises/24-Bottles-Of-Milk/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/24-Bottles-Of-Milk/test.py +++ b/exercises/24-Bottles-Of-Milk/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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/25-Python-Objects/test.py b/exercises/25-Python-Objects/test.py index ec1c2820..0d6ad4d0 100644 --- a/exercises/25-Python-Objects/test.py +++ b/exercises/25-Python-Objects/test.py @@ -2,7 +2,7 @@ import sys sys.stdout = buffer = io.StringIO() -from app import my_function +# from app import my_function import pytest @pytest.mark.it('Your code needs to print hello on the console') @@ -10,12 +10,12 @@ 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('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 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 +# @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 From 199048ff2e3276bb32260ff5109e7a0f805b8348 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 16:10:35 +0000 Subject: [PATCH 29/87] completed 01 --- exercises/01-Console/README.md | 2 +- exercises/01-Console/app.py | 1 + exercises/01-Console/test.py | 15 +++------------ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/exercises/01-Console/README.md b/exercises/01-Console/README.md index 9bddfc8c..fdb43bd7 100644 --- a/exercises/01-Console/README.md +++ b/exercises/01-Console/README.md @@ -12,5 +12,5 @@ print("How are you?") ## πŸ“ Instructions: -Use **print**** to print "Hello World" on the console. Feel free to try other things as well. +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 index 8b137891..3e7cfeb4 100644 --- a/exercises/01-Console/app.py +++ b/exercises/01-Console/app.py @@ -1 +1,2 @@ +print("Hello World!") \ No newline at end of file diff --git a/exercises/01-Console/test.py b/exercises/01-Console/test.py index b80fb1fc..cd70af90 100644 --- a/exercises/01-Console/test.py +++ b/exercises/01-Console/test.py @@ -1,21 +1,12 @@ import io import sys sys.stdout = buffer = io.StringIO() - +import app import pytest -@pytest.mark.it('Your code needs to print hello on the console') +@pytest.mark.it('1. Your code needs to print Hello World! 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('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" + assert captured == "Hello World!\n" #add \n because the console jumps the line on every print -# @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 From 2331eb704f8444489dbd42759238219030c122c0 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 16:11:01 +0000 Subject: [PATCH 30/87] completed 01 --- exercises/01-Console/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/01-Console/app.py b/exercises/01-Console/app.py index 3e7cfeb4..8b137891 100644 --- a/exercises/01-Console/app.py +++ b/exercises/01-Console/app.py @@ -1,2 +1 @@ -print("Hello World!") \ No newline at end of file From b7b45a876b32cc9b4120d173b958f8f19794726f Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 16:17:21 +0000 Subject: [PATCH 31/87] completed 02 --- exercises/02-Declare-Variables/test.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/exercises/02-Declare-Variables/test.py b/exercises/02-Declare-Variables/test.py index 0d6ad4d0..2ecb6555 100644 --- a/exercises/02-Declare-Variables/test.py +++ b/exercises/02-Declare-Variables/test.py @@ -1,21 +1,12 @@ import io import sys sys.stdout = buffer = io.StringIO() - +import app # from app import my_function import pytest -@pytest.mark.it('Your code needs to print hello on the console') +@pytest.mark.it('Your code needs to print Yellow 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('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" + assert captured == "Yellow\n" #add \n because the console jumps the line on every print -# @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 From 863093fbfc9cf6ea7554069fea7240d09056ea68 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 21:17:39 +0000 Subject: [PATCH 32/87] completed 03-04-07 and fixed issues --- .../03-Print-Variables-In-The-Console/test.py | 13 +++++++--- exercises/04-Multiply-Two-Values/test.py | 24 +++++++++---------- exercises/06-Constants/README.md | 4 ++-- exercises/06-Constants/app.py | 5 ++++ exercises/07-String-Concatenation/README.md | 24 ++++++++----------- exercises/07-String-Concatenation/app.py | 11 +++++---- exercises/07-String-Concatenation/test.py | 19 +++++++++++++-- 7 files changed, 62 insertions(+), 38 deletions(-) diff --git a/exercises/03-Print-Variables-In-The-Console/test.py b/exercises/03-Print-Variables-In-The-Console/test.py index 0d6ad4d0..5766361c 100644 --- a/exercises/03-Print-Variables-In-The-Console/test.py +++ b/exercises/03-Print-Variables-In-The-Console/test.py @@ -4,12 +4,19 @@ # from app import my_function import pytest +import app +import os -@pytest.mark.it('Your code needs to print hello on the console') +@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.read() + assert content.find("color") > 0 +@pytest.mark.it('2. You should print on the console the value red ') def test_for_file_output(capsys): captured = buffer.getvalue() - assert captured == "hello\n" #add \n because the console jumps the line on every print - + 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() diff --git a/exercises/04-Multiply-Two-Values/test.py b/exercises/04-Multiply-Two-Values/test.py index 0d6ad4d0..f74f3ca4 100644 --- a/exercises/04-Multiply-Two-Values/test.py +++ b/exercises/04-Multiply-Two-Values/test.py @@ -4,18 +4,18 @@ # from app import my_function import pytest +import os +import app -@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 create a variable named variables_are_cool') +def test_use_variable_name(): -# @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" + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.read() + assert content.find("variables_are_cool") > 0 -# @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 +@pytest.mark.it('2. You should print on the console the variables_are_cool value ') +def test_for_file_output(capsys): + my_result = 2345 *7323 + captured = buffer.getvalue() + assert captured == str(my_result)+'\n' diff --git a/exercises/06-Constants/README.md b/exercises/06-Constants/README.md index 130357ad..681f66be 100644 --- a/exercises/06-Constants/README.md +++ b/exercises/06-Constants/README.md @@ -4,8 +4,8 @@ Since 2015, Javascript also allows the usage of constants, they differ from vari To declare a constant, you have to use the reserved word **const** instead of **var**, like this: -```Javascript -const VERSION = '1.2'; +```py +VERSION = '1.2' ``` Constants are super useful because some times, as a developer, you want to make sure parts of your data are read-only. diff --git a/exercises/06-Constants/app.py b/exercises/06-Constants/app.py index e69de29b..c0356891 100644 --- a/exercises/06-Constants/app.py +++ b/exercises/06-Constants/app.py @@ -0,0 +1,5 @@ +VERSION = '0.1'; + +VERSION = '0.9'; + +print(VERSION); \ No newline at end of file diff --git a/exercises/07-String-Concatenation/README.md b/exercises/07-String-Concatenation/README.md index ddcbf2ff..8105bd6b 100644 --- a/exercises/07-String-Concatenation/README.md +++ b/exercises/07-String-Concatenation/README.md @@ -1,24 +1,20 @@ # `07` String Concatenation -One of Javascript's main objectives is to generate HTML code; concatenation comes in handy -because you can create and add to existing HTML strings. To concatenate strings, we use -the + (plus) operator, for example: - -```Javascript -var one = 'a'; -var two = 'b'; -console.log(one+two); //this will print 'ab' on the console. +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. ``` -Constants are super useful because some times, as a developer, you want to make sure parts of your data are read-only. - ## πŸ“ Instructions: -1. Set the values for myVar1 and myVar2 so the code prints 'Hello World' in the console. +1. Set the values for my_var1 and my_var2 so the code prints 'Hello World' in the console. -## πŸ’‘ Hint: -Here is a 2min video explaining how to concatenate strings and what are they useful for. -https://www.youtube.com/watch?v=cExgK0AnCdM diff --git a/exercises/07-String-Concatenation/app.py b/exercises/07-String-Concatenation/app.py index bb20a140..a9912d19 100644 --- a/exercises/07-String-Concatenation/app.py +++ b/exercises/07-String-Concatenation/app.py @@ -1,8 +1,9 @@ -//Set the values here +# Set the values here +my_var1 = 'Hello' +my_var2 = 'World' - -//Don't change any of this line -var theNewString = myVar1+' '+myVar2 -console.log(theNewString) \ No newline at end of file +## Don't change any of this line +the_new_string = my_var1+' '+my_var2 +print(the_new_string) \ No newline at end of file diff --git a/exercises/07-String-Concatenation/test.py b/exercises/07-String-Concatenation/test.py index 0d6ad4d0..20c0f2af 100644 --- a/exercises/07-String-Concatenation/test.py +++ b/exercises/07-String-Concatenation/test.py @@ -4,11 +4,26 @@ # from app import my_function import pytest +import app +import os -@pytest.mark.it('Your code needs to print hello on the console') + +@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.read() + assert content.find("my_var1") > 0 +@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.read() + assert content.find("my_var2") > 0 +@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\n" #add \n because the console jumps the line on every print + 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): From 494baf0f65fe8f3397f45f634477a05c6897fca2 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Wed, 18 Sep 2019 21:19:05 +0000 Subject: [PATCH 33/87] fixed issues 07 --- exercises/07-String-Concatenation/app.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/exercises/07-String-Concatenation/app.py b/exercises/07-String-Concatenation/app.py index a9912d19..7ca66a63 100644 --- a/exercises/07-String-Concatenation/app.py +++ b/exercises/07-String-Concatenation/app.py @@ -1,9 +1,8 @@ # Set the values here -my_var1 = 'Hello' -my_var2 = 'World' + ## Don't change any of this line the_new_string = my_var1+' '+my_var2 -print(the_new_string) \ No newline at end of file +print(the_new_string) \ No newline at end of file From 67d502023b3e1af464132e46001baa50c9dd88b9 Mon Sep 17 00:00:00 2001 From: Paolo Lucano <paololucanodeveloper@gmail.com> Date: Thu, 19 Sep 2019 15:26:28 +0000 Subject: [PATCH 34/87] completed 08 --- exercises/08-Create-a-Basic-HTML/app.py | 19 ++++++++++--------- exercises/08-Create-a-Basic-HTML/test.py | 12 ++++++++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/exercises/08-Create-a-Basic-HTML/app.py b/exercises/08-Create-a-Basic-HTML/app.py index 508e08cb..805349de 100644 --- a/exercises/08-Create-a-Basic-HTML/app.py +++ b/exercises/08-Create-a-Basic-HTML/app.py @@ -1,10 +1,11 @@ - a = '' - b = '' - c = '' - d = '' - e = '' - f = '' - g = '' - h = '<body>' +a = '' +b = '' +c = '' +d = '' +e = '' +f = '' +g = '' +h = '<body>' + +# DON'T CHANGE THE CODE ABOVE -# DON'T CHANGE THE CODE ABOVE \ No newline at end of file diff --git a/exercises/08-Create-a-Basic-HTML/test.py b/exercises/08-Create-a-Basic-HTML/test.py index 0d6ad4d0..622dde58 100644 --- a/exercises/08-Create-a-Basic-HTML/test.py +++ b/exercises/08-Create-a-Basic-HTML/test.py @@ -4,12 +4,20 @@ # from app import my_function import pytest +import app +import os -@pytest.mark.it('Your code needs to print hello on the console') + +@pytest.mark.it('1. Your code needs to print a basic html layout 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 + 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.read() + assert content.find("html_document") > 0 # @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') # def test_for_function_output(capsys): # my_function() From 6780d10226c102c5e6e4ebcfebc361fad9271826 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 19 Sep 2019 15:31:54 +0000 Subject: [PATCH 35/87] fixed issues 08 --- exercises/08-Create-a-Basic-HTML/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/08-Create-a-Basic-HTML/README.md b/exercises/08-Create-a-Basic-HTML/README.md index a12b41d5..34d69d7d 100644 --- a/exercises/08-Create-a-Basic-HTML/README.md +++ b/exercises/08-Create-a-Basic-HTML/README.md @@ -8,15 +8,15 @@ Let's continue using string concatenation to generate HTML... ## πŸ“ Instructions: 1. The code on the left contains 8 constants with different string values, please use -the constants and concatenate them together to set the value of the variable **htmlDocument** +the constants 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). -Then, print the value of htmlDocument on the console. +Then, print the value of html_document on the console. The output should look like this: -```js +```sh ``` From f6634402965e6f752fc363115981b05c7a4650cf Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 20 Sep 2019 18:49:06 +0000 Subject: [PATCH 36/87] updated 00 --- exercises/00-Welcome/README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/exercises/00-Welcome/README.md b/exercises/00-Welcome/README.md index 803a35e3..ea331a2d 100644 --- a/exercises/00-Welcome/README.md +++ b/exercises/00-Welcome/README.md @@ -1 +1,24 @@ -# Welcome to Python! \ No newline at end of file +# 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 From 9935509e22951ba126f80ffcf5f491b28a4a5dfd Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Tue, 24 Sep 2019 19:53:37 +0000 Subject: [PATCH 37/87] updated 05 --- exercises/05-User-Inputed-Values/app.py | 6 ++++- exercises/05-User-Inputed-Values/test.py | 30 ++++++++++++++---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/exercises/05-User-Inputed-Values/app.py b/exercises/05-User-Inputed-Values/app.py index 2b12f740..2b57fdb8 100644 --- a/exercises/05-User-Inputed-Values/app.py +++ b/exercises/05-User-Inputed-Values/app.py @@ -1 +1,5 @@ -age = int(input('What is your age?')) \ No newline at end of file +age = int(input('What is your age?')) +# YOUR CODE HERE + +# print("Your age is: "+str(int(age)+10)) +print(age+10) \ No newline at end of file diff --git a/exercises/05-User-Inputed-Values/test.py b/exercises/05-User-Inputed-Values/test.py index 0d6ad4d0..cc912d8a 100644 --- a/exercises/05-User-Inputed-Values/test.py +++ b/exercises/05-User-Inputed-Values/test.py @@ -1,21 +1,25 @@ import io import sys sys.stdout = buffer = io.StringIO() - +sys.stdin = buffer = input() # from app import my_function import pytest +import app +import os + +# @pytest.mark.it('1. You should print on the console the input value + 10') +# def test_use_variable_name(): -@pytest.mark.it('Your code needs to print hello on the console') +# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') +# content = f.read() +# assert content.find("console") > 0 +@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\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 + inp = buffer.getvalue() +10 + assert captured == inp+"\n" #add \n because the console jumps the line on every print +# @pytest.mark.it('2. You should print on the console the variables_are_cool value ') +# def test_for_file_output(capsys): +# my_result = 2345 *7323 +# captured = stdin +# assert captured == str(my_result)+'\n' \ No newline at end of file From 6521ffa019b3047eebb41a01bea294dcc8808273 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Tue, 24 Sep 2019 19:54:20 +0000 Subject: [PATCH 38/87] updated 09 --- .../09-Calling-Your-First-Function/README.md | 2 +- .../09-Calling-Your-First-Function/app.py | 10 ++++----- .../09-Calling-Your-First-Function/test.py | 21 +++++++++++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/exercises/09-Calling-Your-First-Function/README.md b/exercises/09-Calling-Your-First-Function/README.md index e8adf395..58942f63 100644 --- a/exercises/09-Calling-Your-First-Function/README.md +++ b/exercises/09-Calling-Your-First-Function/README.md @@ -11,7 +11,7 @@ those after this first Function exercise. (And then, come back). ## πŸ“ Instructions: -1. The function isOdd is defined at the beginning of the code, please call that function passing +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/09-Calling-Your-First-Function/app.py b/exercises/09-Calling-Your-First-Function/app.py index 450b6d9d..c9841f59 100644 --- a/exercises/09-Calling-Your-First-Function/app.py +++ b/exercises/09-Calling-Your-First-Function/app.py @@ -1,6 +1,6 @@ -function isOdd(myNumber) -{ - return !(myNumber % 2 == 0); -} +def is_odd(my_number): + return (my_number % 2 != 0) -//your code here \ No newline at end of file + +# your code here +print(is_odd(45345)) \ No newline at end of file diff --git a/exercises/09-Calling-Your-First-Function/test.py b/exercises/09-Calling-Your-First-Function/test.py index 0d6ad4d0..7430dec3 100644 --- a/exercises/09-Calling-Your-First-Function/test.py +++ b/exercises/09-Calling-Your-First-Function/test.py @@ -4,11 +4,24 @@ # from app import my_function import pytest +import app +import os +# @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('Print "Hello, --Your Name--"') +def test_desired_output(capsys): + app.is_odd(32345) + captured = capsys.readouterr() -@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 + assert captured.out == "true\n" +@pytest.mark.it("Using the conditional statement") +def test_conditional(): + f = open(os.path.dirname(os.path.abspath(__file__))+ '/app.py') + content = f.read() + print("test:",content) + assert content.find("my_number") > 0 # @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') # def test_for_function_output(capsys): From 40c3e55f9f7d8890a6d03bf41a9308cf62358be9 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Tue, 24 Sep 2019 19:55:17 +0000 Subject: [PATCH 39/87] updated 10 --- .../10-Creating-Your-First-Function/README.md | 4 +- .../10-Creating-Your-First-Function/app.py | 8 ++-- .../10-Creating-Your-First-Function/test.py | 40 +++++++++++++++++-- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/exercises/10-Creating-Your-First-Function/README.md b/exercises/10-Creating-Your-First-Function/README.md index c9908bb0..f1953dde 100644 --- a/exercises/10-Creating-Your-First-Function/README.md +++ b/exercises/10-Creating-Your-First-Function/README.md @@ -3,14 +3,14 @@ ## πŸ“ Instructions: -1. The function addNumbers is supposed to return the sum of 2 given numbers, please +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 **"addNumbers"** already declared, it is receiving 2 parameters +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. diff --git a/exercises/10-Creating-Your-First-Function/app.py b/exercises/10-Creating-Your-First-Function/app.py index d8cbe18e..12c41273 100644 --- a/exercises/10-Creating-Your-First-Function/app.py +++ b/exercises/10-Creating-Your-First-Function/app.py @@ -1,7 +1,5 @@ -function addNumbers(a,b) -{ - //your code here +def add_numbers(a,b): + print(a+b) -} -console.log(addNumbers(3,4)) \ No newline at end of file +add_numbers(3,4) \ No newline at end of file diff --git a/exercises/10-Creating-Your-First-Function/test.py b/exercises/10-Creating-Your-First-Function/test.py index 0d6ad4d0..6c1a5d64 100644 --- a/exercises/10-Creating-Your-First-Function/test.py +++ b/exercises/10-Creating-Your-First-Function/test.py @@ -4,12 +4,44 @@ # 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 return the result of a + b ') +# def test_add_number(): +# regex = (r"def add_numbers\(a,b\):\n" +# r" return a\s*\+\s*b") +# # regex = (r"def add_numbers\(a,b\):\n" +# # r" return a\s*\+\s*b") +# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') +# content = f.read() +# print("content", content) +# # matches = re.finditer(regex, content, re.MULTILINE) +# print("matches",regex) + +# assert re.match(regex, content) +@pytest.mark.it('Add all three numbers') +def test_add_variables(capsys): + app.add_numbers(3,4) + captured = capsys.readouterr() + print(captured.out) + + if captured.out == str(7) + "\n": + assert True + else: + assert False +# @pytest.mark.it('2. Your code needs to print 7 on the console') +# def test_for_file_output(capsys): +# my_result = 3+4 +# captured = buffer.getvalue() +# assert captured == str(my_result)+"\n" #add \n because the console jumps the line on every print +# @pytest.mark.it('2. You should print on the console the variables_are_cool value ') +# def test_for_file_output(capsys): +# my_result = 2345 *7323 +# captured = buffer.getvalue() +# assert captured == str(my_result)+'\n' # @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') # def test_for_function_output(capsys): # my_function() From 6eec5557598161af42f2ba78bc1f3795c334699d Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Tue, 24 Sep 2019 19:56:28 +0000 Subject: [PATCH 40/87] updated 11 --- exercises/11-Create-A-New-Function/README.md | 33 +++++++++++++------- exercises/11-Create-A-New-Function/app.py | 1 - exercises/11-Create-A-New-Function/test.py | 30 +++++++++++++++--- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/exercises/11-Create-A-New-Function/README.md b/exercises/11-Create-A-New-Function/README.md index 5370ac63..ccb0dd97 100644 --- a/exercises/11-Create-A-New-Function/README.md +++ b/exercises/11-Create-A-New-Function/README.md @@ -3,30 +3,39 @@ 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: -```js -function addNumbers(a, b){ - return a + b; -} +```py +def add_numbers(a, b): + print(a + b) + ``` -But Javascript comes with a bunch of "pre defined" functions that you can use, for example: +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)) -```js -Math.random(); -} ``` -You can use the Math.random() function to get a random decimal number between 0 and 1, every -time you call that function it will return another random decimal number between 0 and 1. +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 **generateRandom** that generates a random number +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 **Math.random** and **Math.floor** functions. +- 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/11-Create-A-New-Function/app.py b/exercises/11-Create-A-New-Function/app.py index 5214438f..e69de29b 100644 --- a/exercises/11-Create-A-New-Function/app.py +++ b/exercises/11-Create-A-New-Function/app.py @@ -1 +0,0 @@ -# declare your function here \ No newline at end of file diff --git a/exercises/11-Create-A-New-Function/test.py b/exercises/11-Create-A-New-Function/test.py index 0d6ad4d0..81952f26 100644 --- a/exercises/11-Create-A-New-Function/test.py +++ b/exercises/11-Create-A-New-Function/test.py @@ -4,11 +4,33 @@ # from app import my_function import pytest +import os +import app -@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 create a function called generate_random") +def test_use_my_var1(): + + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.read() + assert content.find("def generate_random():") > 0 +@pytest.mark.it("2. You should print a random integer inside generate_random function") +def test_use_print(): + + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.read() + assert content.find("print") > 0 +@pytest.mark.it("3. You should call generate_random function correctly") +def test_call_generate_random(): + + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.read() + assert content.find("generate_random()") > 0 +# @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): From c5b19f31897e210b8f6e89daa23cce938c1f2bf2 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Tue, 24 Sep 2019 19:58:35 +0000 Subject: [PATCH 41/87] updated 12 --- exercises/12-Your-First-If/README.md | 6 +++--- exercises/12-Your-First-If/app.py | 12 +++++++++--- exercises/12-Your-First-If/test.py | 21 +++++++++++++++++---- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/exercises/12-Your-First-If/README.md b/exercises/12-Your-First-If/README.md index 4a0c856a..24faba5a 100644 --- a/exercises/12-Your-First-If/README.md +++ b/exercises/12-Your-First-If/README.md @@ -1,7 +1,7 @@ # `12` Your First if... The current application is prompting asking how much money the user has. Once the user inputs -the amount, we need to **console.log** one of the following answers: +the amount, we need to **print** one of the following answers: @@ -13,5 +13,5 @@ the amount, we need to **console.log** one of the following answers: ## πŸ’‘ Hint: -Use an If/else statement to check the value of the "total" variable. - +- 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/12-Your-First-If/app.py b/exercises/12-Your-First-If/app.py index 4933562f..44e4bd02 100644 --- a/exercises/12-Your-First-If/app.py +++ b/exercises/12-Your-First-If/app.py @@ -1,3 +1,9 @@ -var total = prompt('How much money do you have in your pocket'); - -#your code here \ No newline at end of file +# var total = prompt('How much money do you have in your pocket'); +total = int(input('How much money do you have in your pocket')) +if (total > 100): + print("Give me your money!") +elif (total > 50): + print("Buy me some coffee you cheap!") +elif (total < 51): + print("You are a poor guy, go away!") + \ No newline at end of file diff --git a/exercises/12-Your-First-If/test.py b/exercises/12-Your-First-If/test.py index 0d6ad4d0..7f4f8b61 100644 --- a/exercises/12-Your-First-If/test.py +++ b/exercises/12-Your-First-If/test.py @@ -1,14 +1,27 @@ import io import sys +sys.stdin.buffer.read() sys.stdout = buffer = io.StringIO() # from app import my_function import pytest +import os +import app +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 not delete or change the existing code") +def test_existing_code(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + regex = r"total = int\(input\('How much money do you have in your pocket\?'\)\)" + assert re.match(regex, content[0]) +# @pytest.mark.it('Your code needs to print hello on the console') +# def test_for_file_output(capsys): +# regex = r"print\(random\.rand(\w+)\(10\)\) " +# captured = buffer.getvalue() +# assert captured == regex #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): From 14e0788d16b46ee5280130fc8b0bed932edc59e8 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 25 Sep 2019 16:11:18 +0000 Subject: [PATCH 42/87] updated 13 --- .../13-How-Much-The-Wedding-Costs/app.py | 16 +++++++-- .../13-How-Much-The-Wedding-Costs/test.py | 33 ++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/exercises/13-How-Much-The-Wedding-Costs/app.py b/exercises/13-How-Much-The-Wedding-Costs/app.py index bbf06b72..9654e3ad 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/app.py +++ b/exercises/13-How-Much-The-Wedding-Costs/app.py @@ -1,3 +1,15 @@ -userInput = prompt('How many people are coming to your wedding?'); +# user_input = int(input('How many people are coming to your wedding?')) +user_input = 99 +price = 0 +if( user_input < 51): + price = 4000 +elif (51 < user_input and user_input < 101): + price = 10000 +elif (101 < user_input and user_input < 201): + price = 15000 +else: + price = 20000 -# your code here \ No newline at end of file + +# Your code above here +print('Your wedding will cost '+str(price)+' dollars'); \ No newline at end of file diff --git a/exercises/13-How-Much-The-Wedding-Costs/test.py b/exercises/13-How-Much-The-Wedding-Costs/test.py index 0d6ad4d0..3ca5b943 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/test.py +++ b/exercises/13-How-Much-The-Wedding-Costs/test.py @@ -4,8 +4,39 @@ # 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') + +@pytest.mark.it("1. You should not delete or change the existing code") +def test_existing_code(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + print("####",content[0]) + original_input = r"# user_input = int\(input\('How many people are coming to your wedding\?'\)\)" + assert re.match(original_input, content[0]) + regex = r"print\('Your wedding will cost '\+str\(price\)\+' dollars'\);" + assert re.match(regex, content[(len(content)-1)]) + +@pytest.mark.it("2. You should create a price variable before the if statement") +def test_existingPriceVariable(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] #### With this line of code I removed all the whitespace characters like `\n` at the end of each line + price_variable = r"price = (.+)" + assert re.match(price_variable, content[2]) + # for price in content: + # if price == price_variable: + # assert re.match(price_variable, price) + # for price in content: + # price_index = content.index(price) + # if re.match(price_variable, price_index): + # if price_index < 3: + + + +@pytest.mark.it('3. Your code needs to print the correct outpu 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 From ecaaa7221b8f90d9615642b7968bc33dfea203b8 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 25 Sep 2019 16:30:56 +0000 Subject: [PATCH 43/87] updated 13 and 14 --- .../13-How-Much-The-Wedding-Costs/app.py | 6 ++-- exercises/14-Your-First-Switch/README.md | 36 ++++++++++++++----- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/exercises/13-How-Much-The-Wedding-Costs/app.py b/exercises/13-How-Much-The-Wedding-Costs/app.py index 9654e3ad..38ac731c 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/app.py +++ b/exercises/13-How-Much-The-Wedding-Costs/app.py @@ -1,5 +1,5 @@ -# user_input = int(input('How many people are coming to your wedding?')) -user_input = 99 +user_input = int(input('How many people are coming to your wedding?')) +# user_input = 99 price = 0 if( user_input < 51): price = 4000 @@ -11,5 +11,5 @@ price = 20000 -# Your code above here +# Your code above here print('Your wedding will cost '+str(price)+' dollars'); \ No newline at end of file diff --git a/exercises/14-Your-First-Switch/README.md b/exercises/14-Your-First-Switch/README.md index c54fa40f..558c6762 100644 --- a/exercises/14-Your-First-Switch/README.md +++ b/exercises/14-Your-First-Switch/README.md @@ -1,16 +1,36 @@ # `14` Your First Switch -Imagine your software is running the inventory of a shoe store, a client needs to know in -what colors do you have a particular shoe. - - - +Python does not have a simple switch case construct. Coming from a Javascript or C++ background, you may find this to be a bit odd. +So, to get around this, we use Python’s built-in dictionary construct to implement cases and decided what to do when a case is met. +We can also specify what to do when none is met. + +One way out would be to implement an if-elif-else ladder. Rather, we can use a dictionary to map cases to their functionality. Here, +we define a function week() to tell us which day a certain day of the week is. A switcher is a dictionary that performs this mapping. + +```py +def week(i): + switcher={ + 0:'Sunday', + 1:'Monday', + 2:'Tuesday', + 3:'Wednesday', + 4:'Thursday', + 5:'Friday', + 6:'Saturday' + } + return switcher.get(i,"Invalid day of week") + +``` + +Now, we make calls to week() with different values. + +```py +week(2) + +``` ## πŸ“ Instructions: 1. Complete this switch statement with 3 possible colors: Red, Green and Blue. The function needs to return **true** if the color is available or **false** if the color is not available. -## πŸ’‘ Hint: - -http://www.w3schools.com/js/js_switch.asp \ No newline at end of file From 6f797989dc3a907aa36b31224463fc9667338d7d Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 25 Sep 2019 19:27:40 +0000 Subject: [PATCH 44/87] updated 17 --- exercises/17-Your-First-Loop/app.py | 6 ++++++ exercises/17-Your-First-Loop/test.py | 30 ++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/exercises/17-Your-First-Loop/app.py b/exercises/17-Your-First-Loop/app.py index e69de29b..0ffee236 100644 --- a/exercises/17-Your-First-Loop/app.py +++ b/exercises/17-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/17-Your-First-Loop/test.py b/exercises/17-Your-First-Loop/test.py index 0d6ad4d0..af3016dc 100644 --- a/exercises/17-Your-First-Loop/test.py +++ b/exercises/17-Your-First-Loop/test.py @@ -4,11 +4,33 @@ # from app import my_function import pytest +import os +import app +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 fix the existing code") +def test_existingCode(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.read() + # content = [x.strip() for x in content] #### With this line of code I removed all the whitespace characters like `\n` at the end of each line + # print("$$$$", content) + price_variable = (r"def start_counting\(\): \n" + r"(\s*)for i in range\(101\):\n" + r"(\s*)print\(i\) \n" + r"(\s+)return i\n\n" + r"start_counting\(\)") + assert re.match(price_variable, content) + +# @pytest.mark.it('The console should count from 0 to 100') +# def test_for_file_output(capsys): +# def start_counting(): +# for i in range(101): +# print(i) + +# captured = buffer.getvalue() +# print("test",start_counting()) +# assert captured == str(start_counting())+'\n' # @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') # def test_for_function_output(capsys): From ddbbdc8d530a56284b2c5a447f3366dc9ef692ab Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 18:25:44 +0000 Subject: [PATCH 45/87] updated 15 --- exercises/15-Random-Numbers/README.md | 7 ++----- exercises/15-Random-Numbers/app.py | 13 +++++++------ exercises/15-Random-Numbers/test.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/exercises/15-Random-Numbers/README.md b/exercises/15-Random-Numbers/README.md index 2016ed66..b9b382da 100644 --- a/exercises/15-Random-Numbers/README.md +++ b/exercises/15-Random-Numbers/README.md @@ -1,14 +1,11 @@ # `15` Random Numbers -The **Math.random()** function will return a random decimal number between 0 and 1, run the exercise as it is several times to test it. +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. Now, please update the function code to make it return an integer (no decimals) number between 1 and 10. -## πŸ’‘ Hint: -- Math.random only returns decimal numbers from 0 to 1, and we need Integer numbers from 1 to 10. -- Multiply the Math.random() by 10 to move the decimal 2 slots to the right. -- Use the Math.floor() function to remove the rest of the decimals and have only integers. diff --git a/exercises/15-Random-Numbers/app.py b/exercises/15-Random-Numbers/app.py index 64c42868..2cfa94f5 100644 --- a/exercises/15-Random-Numbers/app.py +++ b/exercises/15-Random-Numbers/app.py @@ -1,8 +1,9 @@ -function getRandomInt() -{ - var randomNumber = Math.floor(Math.random() * 10)+ 1; - return randomNumber; -} +import random +def get_randomInt(): + random_number = random.randrange(10) + return random_number -console.log(getRandomInt()) \ No newline at end of file + + +print(get_randomInt()) \ No newline at end of file diff --git a/exercises/15-Random-Numbers/test.py b/exercises/15-Random-Numbers/test.py index 0d6ad4d0..78f0d31a 100644 --- a/exercises/15-Random-Numbers/test.py +++ b/exercises/15-Random-Numbers/test.py @@ -5,6 +5,23 @@ # from app import my_function import pytest +@pytest.mark.it("1. You should not delete or change the existing code") +def test_existing_code(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + + original_input = r"# user_input = int\(input\('How many people are coming to your wedding\?'\)\)" + assert re.match(original_input, content[0]) + regex = r"print\('Your wedding will cost '\+str\(price\)\+' dollars'\);" + assert re.match(regex, content[(len(content)-1)]) + +@pytest.mark.it("2. You should create a price variable before the if statement") +def test_existingPriceVariable(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] #### With this line of code I removed all the whitespace characters like `\n` at the end of each line + price_variable = r"price = (.+)" + assert re.match(price_variable, content[2]) @pytest.mark.it('Your code needs to print hello on the console') def test_for_file_output(capsys): captured = buffer.getvalue() From 544913e3525ec647cd45066a9dfc5e4e4a6ff866 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 18:26:13 +0000 Subject: [PATCH 46/87] updated 16 --- exercises/16-Rand-From-One-to-Six/app.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/exercises/16-Rand-From-One-to-Six/app.py b/exercises/16-Rand-From-One-to-Six/app.py index e69de29b..4958e622 100644 --- a/exercises/16-Rand-From-One-to-Six/app.py +++ b/exercises/16-Rand-From-One-to-Six/app.py @@ -0,0 +1,9 @@ +import random + +def get_randomInt(): + random_number = random.randrange(7) + return random_number + + + +print(get_randomInt()) \ No newline at end of file From 17448f5de3e8f6b84132061804c833132e842760 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 18:26:51 +0000 Subject: [PATCH 47/87] updated 13 --- exercises/13-How-Much-The-Wedding-Costs/app.py | 4 ++-- exercises/13-How-Much-The-Wedding-Costs/test.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/exercises/13-How-Much-The-Wedding-Costs/app.py b/exercises/13-How-Much-The-Wedding-Costs/app.py index 38ac731c..a3d5838e 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/app.py +++ b/exercises/13-How-Much-The-Wedding-Costs/app.py @@ -1,5 +1,5 @@ -user_input = int(input('How many people are coming to your wedding?')) -# user_input = 99 +# user_input = int(input('How many people are coming to your wedding?')) +user_input = 99 price = 0 if( user_input < 51): price = 4000 diff --git a/exercises/13-How-Much-The-Wedding-Costs/test.py b/exercises/13-How-Much-The-Wedding-Costs/test.py index 3ca5b943..d7593ad3 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/test.py +++ b/exercises/13-How-Much-The-Wedding-Costs/test.py @@ -1,6 +1,5 @@ import io import sys -sys.stdout = buffer = io.StringIO() # from app import my_function import pytest @@ -13,7 +12,7 @@ def test_existing_code(): f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') content = f.readlines() - print("####",content[0]) + original_input = r"# user_input = int\(input\('How many people are coming to your wedding\?'\)\)" assert re.match(original_input, content[0]) regex = r"print\('Your wedding will cost '\+str\(price\)\+' dollars'\);" @@ -37,9 +36,13 @@ def test_existingPriceVariable(): @pytest.mark.it('3. Your code needs to print the correct outpu 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 +def test_for_file_output(): + # sys.stdout = buffer = io.StringIO() + test =sys.stdin.read() + # captured = buffer.getvalue() + # print("####",buffer.getvalue()) + print("$$$$",test) + # 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): From 5d7c3818c945c4c510ed84d55b53e9b9d508f5e6 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 18:27:17 +0000 Subject: [PATCH 48/87] updated 14 --- exercises/14-Your-First-Switch/app.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/14-Your-First-Switch/app.py b/exercises/14-Your-First-Switch/app.py index 4f42eeb0..d5ab1210 100644 --- a/exercises/14-Your-First-Switch/app.py +++ b/exercises/14-Your-First-Switch/app.py @@ -1,12 +1,12 @@ -function getColor(selection) -{ +def getColor(selection): + switch(selection){ //Add more options here default : return false;//return false because the user pick a unavailable color - break; - } -} + break + + var colorname = window.prompt('What color do you want?'); var isAvailable = getColor(colorname); From c88878abfb7be4ac23fe61ca9fec882f176f8171 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 18:27:53 +0000 Subject: [PATCH 49/87] updated 18 --- exercises/18-Create-A-For-Loop/README.md | 8 ++++++-- exercises/18-Create-A-For-Loop/app.py | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/exercises/18-Create-A-For-Loop/README.md b/exercises/18-Create-A-For-Loop/README.md index 319f41f1..17393992 100644 --- a/exercises/18-Create-A-For-Loop/README.md +++ b/exercises/18-Create-A-For-Loop/README.md @@ -6,9 +6,13 @@ The "**for**" loop lets you run the same code for different values. Read more on loops: ```sh -https://www.w3schools.com/js/js_loop_for.asp +https://www.w3schools.com/python/python_for_loops.asp ``` ## πŸ“ Instructions: -1. Create a function called **standardsMaker** that prints 300 times the phrase "I will write questions if I'm stuck". +1. Create a function called **standards_maker** that prints 300 times the phrase "I will write questions if I'm stuck". + +## πŸ’‘ Hint: + +- You can use the range() function in the for loop. \ No newline at end of file diff --git a/exercises/18-Create-A-For-Loop/app.py b/exercises/18-Create-A-For-Loop/app.py index e69de29b..b2c06d24 100644 --- a/exercises/18-Create-A-For-Loop/app.py +++ b/exercises/18-Create-A-For-Loop/app.py @@ -0,0 +1,4 @@ +def standard_maker(): + for x in range(300): + print("I will write questions if I'm stuck") +standard_maker() \ No newline at end of file From 790bff9e83e87dd4d51e9369f2a692e9c97c6421 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 18:28:32 +0000 Subject: [PATCH 50/87] updated 20 --- exercises/20-Random-Colors-Loop/README.md | 12 +++------ exercises/20-Random-Colors-Loop/app.py | 30 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/exercises/20-Random-Colors-Loop/README.md b/exercises/20-Random-Colors-Loop/README.md index a46a2d15..6fca6bcb 100644 --- a/exercises/20-Random-Colors-Loop/README.md +++ b/exercises/20-Random-Colors-Loop/README.md @@ -8,18 +8,12 @@ Let's say that we are teachers in a 10 student classroom and we want to randomly (only ONE color PER student) -1. Change the function "**getAllStudentColors**" so it returns an array of 10 colors, with each item in the array representing the color assigned to each 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 **Math.random()** function we saw on the last exercise. -- Use the "**getColor**" function on this exercise to get the color name from the number you get. +- 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. -## IMPORTANT MESSAGE: - -If you feel you are not understanding looping, its a good idea to complete the Arrays Exercises classroom and then come back here: -```sh -https://repl.it/classroom/invite/BB4WDpk -``` \ No newline at end of file diff --git a/exercises/20-Random-Colors-Loop/app.py b/exercises/20-Random-Colors-Loop/app.py index e69de29b..8220bf38 100644 --- a/exercises/20-Random-Colors-Loop/app.py +++ b/exercises/20-Random-Colors-Loop/app.py @@ -0,0 +1,30 @@ +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(): + + #your loop here + example_color = 1 + students_array = [] + + for i in range(11): + example_color = get_color(random.randint(0,4)) + students_array.append(example_color) + return students_array + + + +print(get_allStudentColors()) \ No newline at end of file From 7a74ef87bae2ac198d2828700ea12fe8ab9c2298 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 18:29:07 +0000 Subject: [PATCH 51/87] updated 21 --- exercises/21-Looping-With-FizzBuzz/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/21-Looping-With-FizzBuzz/README.md b/exercises/21-Looping-With-FizzBuzz/README.md index 7b784c1f..c4c89881 100644 --- a/exercises/21-Looping-With-FizzBuzz/README.md +++ b/exercises/21-Looping-With-FizzBuzz/README.md @@ -11,9 +11,9 @@ Write the code needed to print in the console all the numbers from 1 to 100. Example output: -```js -/* output -1 +```py + + + ``` From 640bd6f754348294bc0ee405fc28a9b1902d6ff5 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 18:29:23 +0000 Subject: [PATCH 52/87] updated 12 --- exercises/12-Your-First-If/app.py | 6 ++-- exercises/12-Your-First-If/test.py | 51 ++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/exercises/12-Your-First-If/app.py b/exercises/12-Your-First-If/app.py index 44e4bd02..7d097d9d 100644 --- a/exercises/12-Your-First-If/app.py +++ b/exercises/12-Your-First-If/app.py @@ -1,9 +1,9 @@ -# var total = prompt('How much money do you have in your pocket'); + total = int(input('How much money do you have in your pocket')) + if (total > 100): print("Give me your money!") elif (total > 50): print("Buy me some coffee you cheap!") elif (total < 51): - print("You are a poor guy, go away!") - \ No newline at end of file + print("You are a poor guy, go away!") diff --git a/exercises/12-Your-First-If/test.py b/exercises/12-Your-First-If/test.py index 7f4f8b61..9634bd34 100644 --- a/exercises/12-Your-First-If/test.py +++ b/exercises/12-Your-First-If/test.py @@ -1,22 +1,41 @@ -import io -import sys -sys.stdin.buffer.read() -sys.stdout = buffer = io.StringIO() - # from app import my_function -import pytest -import os -import app -import re - - +import pytest,os,re,io,sys, mock, json @pytest.mark.it("1. You should not delete or change the existing code") -def test_existing_code(): - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - content = f.readlines() - regex = r"total = int\(input\('How much money do you have in your pocket\?'\)\)" - assert re.match(regex, content[0]) +def test_t(stdin): + _input = json.loads(stdin) + print("####", _input) + 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 + # content = f.readlines() + # regex = r"total = int\(input\('How much money do you have in your pocket\?'\)\)" + # assert re.match(regex, content[0]) + assert "Give me your money!\n" == buffer.getvalue() +# @pytest.mark.it("2. You should not delete or change the existing code") +# def test_e(stdin): +# _input = json.loads(stdin) +# 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 +# # content = f.readlines() +# # regex = r"total = int\(input\('How much money do you have in your pocket\?'\)\)" +# # assert re.match(regex, content[0]) +# assert "Buy me some coffee you cheap!\n" == buffer.getvalue() +# @pytest.mark.it("3. You should not delete or change the existing code") +# def test_w(stdin): +# _input = json.loads(stdin) +# 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 +# # content = f.readlines() +# # regex = r"total = int\(input\('How much money do you have in your pocket\?'\)\)" +# # assert re.match(regex, content[0]) +# assert "You are a poor guy, go away!\n" == buffer.getvalue() + # @pytest.mark.it('Your code needs to print hello on the console') # def test_for_file_output(capsys): # regex = r"print\(random\.rand(\w+)\(10\)\) " From 4698f63b8d496d8ff9a2596932230be6e7c52466 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 21:03:34 +0000 Subject: [PATCH 53/87] updated 21 --- exercises/21-Looping-With-FizzBuzz/README.md | 4 ++-- exercises/21-Looping-With-FizzBuzz/app.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/exercises/21-Looping-With-FizzBuzz/README.md b/exercises/21-Looping-With-FizzBuzz/README.md index c4c89881..ad7fe2c6 100644 --- a/exercises/21-Looping-With-FizzBuzz/README.md +++ b/exercises/21-Looping-With-FizzBuzz/README.md @@ -13,7 +13,7 @@ Example output: ```py - +Buzz ``` diff --git a/exercises/21-Looping-With-FizzBuzz/app.py b/exercises/21-Looping-With-FizzBuzz/app.py index e69de29b..d0c043c6 100644 --- a/exercises/21-Looping-With-FizzBuzz/app.py +++ b/exercises/21-Looping-With-FizzBuzz/app.py @@ -0,0 +1,15 @@ + +# print('\n'.join("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i) for i in range(1,101))) +def fizz_buzz(): + # your code here + for i in range(1,101): + if(i % 3 == 0 and i % 5 == 0): + print("FizzBuzz") + elif(i % 3 == 0): + print("Fizz") + elif(i % 5 == 0): + print("Buzz") + else: + print(i) + +fizz_buzz(); \ No newline at end of file From 5fe14a64bec98dbe24e8536e17946e0372c12dbd Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 21:09:09 +0000 Subject: [PATCH 54/87] updated 22 --- exercises/22-Russian-Roulette/README.md | 2 +- exercises/22-Russian-Roulette/app.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/exercises/22-Russian-Roulette/README.md b/exercises/22-Russian-Roulette/README.md index 9033fe26..5084b1fc 100644 --- a/exercises/22-Russian-Roulette/README.md +++ b/exercises/22-Russian-Roulette/README.md @@ -9,7 +9,7 @@ FIRE!!!....... are you dead? ## πŸ“ Instructions: -1. The game is almost working, please fill the function "**fireGun**" to make the game work +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.) diff --git a/exercises/22-Russian-Roulette/app.py b/exercises/22-Russian-Roulette/app.py index e69de29b..734e9bee 100644 --- a/exercises/22-Russian-Roulette/app.py +++ b/exercises/22-Russian-Roulette/app.py @@ -0,0 +1,20 @@ +import random + +bullet_position = 3 + +def spin_chamber(): + chamber_position = random.randint(1,6) + return chamber_position + + +def fire_gun(): + #you code here + if(spin_chamber() == bullet_position): + return False + else: + return True + + + +if(fire_gun()): print('Keep playing :)') +else: print('You are dead!') \ No newline at end of file From c7fe498e1dbbe6d8060117e938e22d2b049b8480 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Thu, 26 Sep 2019 21:14:25 +0000 Subject: [PATCH 55/87] updated 23 --- exercises/23-The-Beatles/app.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/exercises/23-The-Beatles/app.py b/exercises/23-The-Beatles/app.py index e69de29b..8f3437a7 100644 --- a/exercises/23-The-Beatles/app.py +++ b/exercises/23-The-Beatles/app.py @@ -0,0 +1,12 @@ +# Your code here!! +def sing(): + + repeated_text = "" + final_string = "" + for i in range(1,5): + repeated_text += "let it be, \n" + final_string = repeated_text + "Whisper words of wisdom, let it be, " + repeated_text + "there will be an answer, " + "let it be" + return final_string + + +print(sing()) \ No newline at end of file From 0feaf3f8c9f1730edce664a3c4d424d8f3073db8 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 27 Sep 2019 15:30:44 +0000 Subject: [PATCH 56/87] updated 24 --- exercises/24-Bottles-Of-Milk/app.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/exercises/24-Bottles-Of-Milk/app.py b/exercises/24-Bottles-Of-Milk/app.py index e69de29b..d54ef86d 100644 --- a/exercises/24-Bottles-Of-Milk/app.py +++ b/exercises/24-Bottles-Of-Milk/app.py @@ -0,0 +1,20 @@ +def number_of_bottles(): + plural_line = "" + second_line = "" + sing_line = "" + last_line = "" + for i in range(100,0,-1): + + if i>2: + plural_line += str(i) + " bottles of milk on the wall, " + str(i) + " bottles of milk."+ "\n" + "Take one down and pass it around, " + str(i-1) + " bottles of milk on the wall."+ "\n" + elif i == 2: + second_line += str(i) + " bottles of milk on the wall, " + str(i) + " bottles of milk."+ "\n" + "Take one down and pass it around, " + str(i-1) +" bottle of milk on the wall."+ "\n" + elif i == 1: + sing_line += str(i) + " bottle of milk on the wall, " + str(i) + " bottle of milk."+ "\n" + "Take one down and pass it around, " + "no more bottles of milk on the wall."+ "\n" + else: + last_line = "No more bottles of milk on the wall, no more bottles of milk." +"\n"+"Go to the store and buy some more, "+ str(i+99) +" bottles of milk on the wall." + + return plural_line + second_line + sing_line + last_line + + +print(number_of_bottles()) \ No newline at end of file From e4d881cd051391f07b95ca7fc81ab44253cd25af Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 27 Sep 2019 20:23:10 +0000 Subject: [PATCH 57/87] updated 25 --- exercises/25-Python-Objects/README.md | 59 +++++++++++---------------- exercises/25-Python-Objects/app.py | 51 +++++++++++++++++++++++ exercises/25-Python-Objects/test.py | 29 ++++++++++++- 3 files changed, 102 insertions(+), 37 deletions(-) diff --git a/exercises/25-Python-Objects/README.md b/exercises/25-Python-Objects/README.md index 59d735df..95864407 100644 --- a/exercises/25-Python-Objects/README.md +++ b/exercises/25-Python-Objects/README.md @@ -1,44 +1,37 @@ -# `25` Javascript Objects +# `25` 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: -```Javascript -var car1Model = "corolla"; -var car1Make = "Toyota"; -var car1Color = "green"; -var car1Year = 2015; - -var car2Model = "santa fe"; -var car2Make = "Hyundai"; -var car2Color = "purple"; -var car2Year = 2013; -//... (you get the idea) +```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: -```js -var car1 = { model: "corolla", make: "toyota", color: "green", year: 2015}; +```py +class ClassName: + def __init__(): + self.model = "Corolla" + self.make = "Toyota" + self.color = "Green" + self.year = "2015" ``` -You can see the key: value separated by a comma. - -And for us (developers) to read it easier we write it like this: - -```js -var car1 = { - model: "corolla", - make: "toyota", - color: "green", - 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: @@ -70,8 +63,8 @@ var family = { ``` So, if on this scenario if we want to know the name of the first member of the Doe family we do: -```js -console.log(family.members[0].name); +```py +print(family.members[0].name); ``` Or the 3rd lucky number of the significant other of the second member of Doe's family: @@ -82,12 +75,8 @@ console.log( family.members[1].significant_other.lucky_numbers[2]); Easy stuff :) ## πŸ“ Instructions: -1. Programmatically, change the fourth lucky number of John Doe to 33 (use a command, don't manually change the code) -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. Now please print ( console.log() ) the SUM of all of the lucky numbers of the Doe family. +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** Now please print ( console.log() ) the SUM of all of the lucky numbers of the Doe family. -## πŸ’‘ Hint: -- You can get each array of lucky numbers from each person object inside the family object. -- Once you get each array just loop over it adding every element (like we've been doing so far). And then add each sum of the 3 family members. -- Null is also an object. diff --git a/exercises/25-Python-Objects/app.py b/exercises/25-Python-Objects/app.py index e69de29b..cf963245 100644 --- a/exercises/25-Python-Objects/app.py +++ b/exercises/25-Python-Objects/app.py @@ -0,0 +1,51 @@ +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] + + +# STEP 1 Change the fourth lucky number of John Doe to 33 + +Person.lucky_numbers[3] = 33 + +# STEP 2 Create Little Jimmy's object + +class Person_3: + name = "Jimmy" + lastname = "Doe" + age = 13 + gender = "female" + lucky_numbers = [ 1, 2, 3, 4] + significant_other = None + +class Family: + lastname = "Doe" + members = [Person, Person_2] #Array of objects, don't forget to add Jimmy + +# STEP 3 Add Jimmy to Family object + +Family.members.append(Person_3) + +def add_allFamilyLuckyNumbers(an_array): + sum_ofAllLuckyNumbers = 0 # sum_ofAllLuckyNumbers is a number, the sum of all lucky numbers. + temp = 0 + for i in Family.members: + for x in i.lucky_numbers: + sum_ofAllLuckyNumbers += x + + return sum_ofAllLuckyNumbers + +print(add_allFamilyLuckyNumbers(Family.members)) #Step 3 + + + diff --git a/exercises/25-Python-Objects/test.py b/exercises/25-Python-Objects/test.py index 0d6ad4d0..c294dc3b 100644 --- a/exercises/25-Python-Objects/test.py +++ b/exercises/25-Python-Objects/test.py @@ -4,11 +4,36 @@ # 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') +@pytest.mark.it("1. You should not delete or change the existing code") +def test_existing_code(): + f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') + content = f.readlines() + content = [x.strip() for x in content] + print("@@@@",content) + + original_input = [ + r"class Person:", + r"(\s*)name = \"John\"", + r"(\s*)lastname = \"Doe\"", + r"(\s*)age = 35", + r"(\s*)gender = \"male\"", + r"(\s*)lucky_numbers = \[ 7, 11, 13, 17]" + ] + print("$$$$$$",[i for i, j in zip(original_input, content) if i == j ]) + + + # regex = r"print\('Your wedding will cost '\+str\(price\)\+' dollars'\);" + # assert re.match(regex, content[(len(content)-1)]) + + +@pytest.mark.it('Your code needs to print the correct sum 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 + 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): From 69336d0f4c973678cd29bc9e3ac2c3431b7c60cc Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 27 Sep 2019 20:58:52 +0000 Subject: [PATCH 58/87] updated 25 --- .../13-How-Much-The-Wedding-Costs/test.py | 2 +- exercises/25-Python-Objects/app.py | 25 +++++++++---------- exercises/25-Python-Objects/test.py | 11 ++++++-- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/exercises/13-How-Much-The-Wedding-Costs/test.py b/exercises/13-How-Much-The-Wedding-Costs/test.py index d7593ad3..0420c881 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/test.py +++ b/exercises/13-How-Much-The-Wedding-Costs/test.py @@ -23,7 +23,7 @@ def test_existingPriceVariable(): f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') content = f.readlines() content = [x.strip() for x in content] #### With this line of code I removed all the whitespace characters like `\n` at the end of each line - price_variable = r"price = (.+)" + price_variable = r"price = (.+)" assert re.match(price_variable, content[2]) # for price in content: # if price == price_variable: diff --git a/exercises/25-Python-Objects/app.py b/exercises/25-Python-Objects/app.py index cf963245..7ba3d36f 100644 --- a/exercises/25-Python-Objects/app.py +++ b/exercises/25-Python-Objects/app.py @@ -12,13 +12,19 @@ class Person_2: 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 Person.lucky_numbers[3] = 33 -# STEP 2 Create Little Jimmy's object +# STEP 2 Create Little Jimmy's object and then add it to the family object +# Your code here class Person_3: name = "Jimmy" @@ -26,14 +32,7 @@ class Person_3: age = 13 gender = "female" lucky_numbers = [ 1, 2, 3, 4] - significant_other = None - -class Family: - lastname = "Doe" - members = [Person, Person_2] #Array of objects, don't forget to add Jimmy - -# STEP 3 Add Jimmy to Family object - + Family.members.append(Person_3) def add_allFamilyLuckyNumbers(an_array): @@ -45,7 +44,7 @@ def add_allFamilyLuckyNumbers(an_array): return sum_ofAllLuckyNumbers -print(add_allFamilyLuckyNumbers(Family.members)) #Step 3 - - +# STEP 3 Print the sum of all the lucky numbers of the Doe's family +# Your code here +print(add_allFamilyLuckyNumbers(Family.members)) \ No newline at end of file diff --git a/exercises/25-Python-Objects/test.py b/exercises/25-Python-Objects/test.py index c294dc3b..ef7804ff 100644 --- a/exercises/25-Python-Objects/test.py +++ b/exercises/25-Python-Objects/test.py @@ -30,10 +30,17 @@ def test_existing_code(): # assert re.match(regex, content[(len(content)-1)]) -@pytest.mark.it('Your code needs to print the correct sum on the console') + +@pytest.mark.it('STEP 3. Your code needs to print the correct sum on the console') def test_for_file_output(capsys): captured = buffer.getvalue() - assert captured == str(94)+'\n' + 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\(add_allFamilyLuckyNumbers\(Family\.members\)\) " + assert re.match(regex, content[(len(content)-1)]) + # 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): From 79757da5381a0513f7e7b22b428062319e8d18ba Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 27 Sep 2019 21:01:11 +0000 Subject: [PATCH 59/87] updated 24 --- exercises/24-Bottles-Of-Milk/test.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/exercises/24-Bottles-Of-Milk/test.py b/exercises/24-Bottles-Of-Milk/test.py index 0d6ad4d0..e2e3a9bd 100644 --- a/exercises/24-Bottles-Of-Milk/test.py +++ b/exercises/24-Bottles-Of-Milk/test.py @@ -4,12 +4,19 @@ # from app import my_function import pytest +import os +import app +import re -@pytest.mark.it('Your code needs to print hello on the console') +@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() - assert captured == "hello\n" #add \n because the console jumps the line on every print - + 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\(number_of_bottles\(\)\)" + 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() From 59eba4b8ef8e8388a518a2069a840ad3e2b63572 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 27 Sep 2019 21:02:31 +0000 Subject: [PATCH 60/87] updated 23 --- exercises/23-The-Beatles/test.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/exercises/23-The-Beatles/test.py b/exercises/23-The-Beatles/test.py index 0d6ad4d0..b9649961 100644 --- a/exercises/23-The-Beatles/test.py +++ b/exercises/23-The-Beatles/test.py @@ -4,12 +4,19 @@ # from app import my_function import pytest +import os +import app +import re -@pytest.mark.it('Your code needs to print hello on the console') +@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() - assert captured == "hello\n" #add \n because the console jumps the line on every print - + 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\(sing\(\)\)" + 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() From 8d2d02bd2cd1f97c92571167304eed3a7eb794d0 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 27 Sep 2019 21:04:42 +0000 Subject: [PATCH 61/87] updated 21 --- exercises/21-Looping-With-FizzBuzz/app.py | 2 +- exercises/21-Looping-With-FizzBuzz/test.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/exercises/21-Looping-With-FizzBuzz/app.py b/exercises/21-Looping-With-FizzBuzz/app.py index d0c043c6..7a0c1c6a 100644 --- a/exercises/21-Looping-With-FizzBuzz/app.py +++ b/exercises/21-Looping-With-FizzBuzz/app.py @@ -12,4 +12,4 @@ def fizz_buzz(): else: print(i) -fizz_buzz(); \ No newline at end of file +fizz_buzz() \ No newline at end of file diff --git a/exercises/21-Looping-With-FizzBuzz/test.py b/exercises/21-Looping-With-FizzBuzz/test.py index 0d6ad4d0..be66a339 100644 --- a/exercises/21-Looping-With-FizzBuzz/test.py +++ b/exercises/21-Looping-With-FizzBuzz/test.py @@ -4,11 +4,19 @@ # 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') +@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() - assert captured == "hello\n" #add \n because the console jumps the line on every print + 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"fizz_buzz\(\)" + 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): From ee9965f25433cbd189656bb69bbd9574be2dcf82 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 27 Sep 2019 21:06:12 +0000 Subject: [PATCH 62/87] updated 20 --- exercises/20-Random-Colors-Loop/test.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exercises/20-Random-Colors-Loop/test.py b/exercises/20-Random-Colors-Loop/test.py index 0d6ad4d0..57544005 100644 --- a/exercises/20-Random-Colors-Loop/test.py +++ b/exercises/20-Random-Colors-Loop/test.py @@ -4,11 +4,19 @@ # 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') +@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() - assert captured == "hello\n" #add \n because the console jumps the line on every print + 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): From 3f42207ba7c588812d77e5b655766f6b9dd2301c Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Mon, 30 Sep 2019 21:41:49 +0000 Subject: [PATCH 63/87] updated 22 --- exercises/22-Russian-Roulette/app.py | 11 +++++------ exercises/22-Russian-Roulette/test.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/exercises/22-Russian-Roulette/app.py b/exercises/22-Russian-Roulette/app.py index 734e9bee..d9c3b432 100644 --- a/exercises/22-Russian-Roulette/app.py +++ b/exercises/22-Russian-Roulette/app.py @@ -10,11 +10,10 @@ def spin_chamber(): def fire_gun(): #you code here if(spin_chamber() == bullet_position): - return False + return 'Keep playing :)' else: - return True - - + return 'You are dead!' -if(fire_gun()): print('Keep playing :)') -else: print('You are dead!') \ No newline at end of file + + +print(fire_gun()) \ No newline at end of file diff --git a/exercises/22-Russian-Roulette/test.py b/exercises/22-Russian-Roulette/test.py index 0d6ad4d0..92e43e4a 100644 --- a/exercises/22-Russian-Roulette/test.py +++ b/exercises/22-Russian-Roulette/test.py @@ -4,11 +4,19 @@ # from app import my_function import pytest +import app +import re +import os -@pytest.mark.it('Your code needs to print hello on the console') +@pytest.mark.it('STEP 1. Your code needs to print the correct output 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 + 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\(fire_gun\(\)\)" + 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): From 69466225b4d143e6c090988fdc3f9a11f97d7613 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 16:39:43 +0000 Subject: [PATCH 64/87] fixed issues 01-02-03-13 --- exercises/01-Console/app.py | 2 +- exercises/02-Declare-Variables/app.py | 3 ++- exercises/02-Declare-Variables/test.py | 14 +++++++++++++- exercises/03-Print-Variables-In-The-Console/app.py | 3 ++- .../03-Print-Variables-In-The-Console/test.py | 9 +++++++-- exercises/13-How-Much-The-Wedding-Costs/test.py | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/exercises/01-Console/app.py b/exercises/01-Console/app.py index 8b137891..f301245e 100644 --- a/exercises/01-Console/app.py +++ b/exercises/01-Console/app.py @@ -1 +1 @@ - +print("Hello World!") diff --git a/exercises/02-Declare-Variables/app.py b/exercises/02-Declare-Variables/app.py index 8b137891..00be7bf1 100644 --- a/exercises/02-Declare-Variables/app.py +++ b/exercises/02-Declare-Variables/app.py @@ -1 +1,2 @@ - +name = "Yellow" +print(name) \ No newline at end of file diff --git a/exercises/02-Declare-Variables/test.py b/exercises/02-Declare-Variables/test.py index 2ecb6555..9ba4957f 100644 --- a/exercises/02-Declare-Variables/test.py +++ b/exercises/02-Declare-Variables/test.py @@ -4,8 +4,20 @@ import app # from app import my_function import pytest +import os +import re -@pytest.mark.it('Your code needs to print Yellow on the console') +# @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): 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/app.py b/exercises/03-Print-Variables-In-The-Console/app.py index 8b137891..04b067d9 100644 --- a/exercises/03-Print-Variables-In-The-Console/app.py +++ b/exercises/03-Print-Variables-In-The-Console/app.py @@ -1 +1,2 @@ - +color = "red" +print(color) diff --git a/exercises/03-Print-Variables-In-The-Console/test.py b/exercises/03-Print-Variables-In-The-Console/test.py index 5766361c..3f9859ea 100644 --- a/exercises/03-Print-Variables-In-The-Console/test.py +++ b/exercises/03-Print-Variables-In-The-Console/test.py @@ -6,13 +6,18 @@ 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.read() - assert content.find("color") > 0 + 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): captured = buffer.getvalue() diff --git a/exercises/13-How-Much-The-Wedding-Costs/test.py b/exercises/13-How-Much-The-Wedding-Costs/test.py index 0420c881..d7593ad3 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/test.py +++ b/exercises/13-How-Much-The-Wedding-Costs/test.py @@ -23,7 +23,7 @@ def test_existingPriceVariable(): f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') content = f.readlines() content = [x.strip() for x in content] #### With this line of code I removed all the whitespace characters like `\n` at the end of each line - price_variable = r"price = (.+)" + price_variable = r"price = (.+)" assert re.match(price_variable, content[2]) # for price in content: # if price == price_variable: From 62db4c9c3accfec6763763475f21d533252c1478 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 17:10:10 +0000 Subject: [PATCH 65/87] fixed issues 04 --- exercises/04-Multiply-Two-Values/README.md | 3 ++- exercises/04-Multiply-Two-Values/app.py | 3 ++- exercises/04-Multiply-Two-Values/test.py | 21 ++++++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/exercises/04-Multiply-Two-Values/README.md b/exercises/04-Multiply-Two-Values/README.md index 9e497129..7e954c59 100644 --- a/exercises/04-Multiply-Two-Values/README.md +++ b/exercises/04-Multiply-Two-Values/README.md @@ -10,7 +10,8 @@ In this case, we stored the result value of the multiplication into a variable c ## πŸ“ Instructions: -1. Please store the result of multiplying 2345 times 7323 in a variable called **variables_are_cool** and the print the result in the console. +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 index 8b137891..b8b6971b 100644 --- a/exercises/04-Multiply-Two-Values/app.py +++ b/exercises/04-Multiply-Two-Values/app.py @@ -1 +1,2 @@ - +variables_are_cool = 2345 * 7323 +print(variables_are_cool) \ No newline at end of file diff --git a/exercises/04-Multiply-Two-Values/test.py b/exercises/04-Multiply-Two-Values/test.py index f74f3ca4..ea84ce4e 100644 --- a/exercises/04-Multiply-Two-Values/test.py +++ b/exercises/04-Multiply-Two-Values/test.py @@ -6,16 +6,31 @@ 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.read() - assert content.find("variables_are_cool") > 0 + 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\(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]) From 8cafcd7c382016ff1a6c47e7ffe26e9544cbdc1f Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 17:53:32 +0000 Subject: [PATCH 66/87] fixed issues 05 --- exercises/05-User-Inputed-Values/app.py | 4 +-- exercises/05-User-Inputed-Values/test.py | 37 +++++++++--------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/exercises/05-User-Inputed-Values/app.py b/exercises/05-User-Inputed-Values/app.py index 2b57fdb8..971faa7b 100644 --- a/exercises/05-User-Inputed-Values/app.py +++ b/exercises/05-User-Inputed-Values/app.py @@ -1,5 +1,5 @@ age = int(input('What is your age?')) # YOUR CODE HERE -# print("Your age is: "+str(int(age)+10)) -print(age+10) \ No newline at end of file +print("Your age is: "+str(int(age)+10)) +# print(age+10) \ No newline at end of file diff --git a/exercises/05-User-Inputed-Values/test.py b/exercises/05-User-Inputed-Values/test.py index cc912d8a..74e1cb34 100644 --- a/exercises/05-User-Inputed-Values/test.py +++ b/exercises/05-User-Inputed-Values/test.py @@ -1,25 +1,14 @@ -import io -import sys -sys.stdout = buffer = io.StringIO() -sys.stdin = buffer = input() -# from app import my_function -import pytest -import app -import os +import pytest,os,re,io,sys, mock, json -# @pytest.mark.it('1. You should print on the console the input value + 10') -# def test_use_variable_name(): - -# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') -# content = f.read() -# assert content.find("console") > 0 -@pytest.mark.it('3. Your code needs to print Hello World on the console') -def test_for_file_output(capsys): - captured = buffer.getvalue() - inp = buffer.getvalue() +10 - assert captured == inp+"\n" #add \n because the console jumps the line on every print -# @pytest.mark.it('2. You should print on the console the variables_are_cool value ') -# def test_for_file_output(capsys): -# my_result = 2345 *7323 -# captured = stdin -# assert captured == str(my_result)+'\n' \ No newline at end of file +@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' From 7da8203d3adc54a2bfa163d4aa3392cc6bd425a6 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 18:04:09 +0000 Subject: [PATCH 67/87] fixed issues 07 --- exercises/07-String-Concatenation/app.py | 4 +--- exercises/07-String-Concatenation/test.py | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/exercises/07-String-Concatenation/app.py b/exercises/07-String-Concatenation/app.py index 7ca66a63..237c9d46 100644 --- a/exercises/07-String-Concatenation/app.py +++ b/exercises/07-String-Concatenation/app.py @@ -1,8 +1,6 @@ # Set the values here - - -## Don't change any of this line +## 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/07-String-Concatenation/test.py b/exercises/07-String-Concatenation/test.py index 20c0f2af..a3a37b2c 100644 --- a/exercises/07-String-Concatenation/test.py +++ b/exercises/07-String-Concatenation/test.py @@ -22,6 +22,7 @@ def test_use_my_var2(): assert content.find("my_var2") > 0 @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 From 71d4172d2daffc5ecada92d34aa0184d705742f0 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 18:13:42 +0000 Subject: [PATCH 68/87] fixed issues 08 --- exercises/08-Create-a-Basic-HTML/README.md | 6 +++--- exercises/08-Create-a-Basic-HTML/app.py | 2 ++ exercises/08-Create-a-Basic-HTML/test.py | 10 ++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/exercises/08-Create-a-Basic-HTML/README.md b/exercises/08-Create-a-Basic-HTML/README.md index 34d69d7d..6e4b683e 100644 --- a/exercises/08-Create-a-Basic-HTML/README.md +++ b/exercises/08-Create-a-Basic-HTML/README.md @@ -7,12 +7,12 @@ Let's continue using string concatenation to generate HTML... ## πŸ“ Instructions: -1. The code on the left contains 8 constants with different string values, please use -the constants and concatenate them together to set the value of the variable **html_document** +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). -Then, print the value of html_document on the console. +2. Then, print the value of html_document on the console. The output should look like this: diff --git a/exercises/08-Create-a-Basic-HTML/app.py b/exercises/08-Create-a-Basic-HTML/app.py index 805349de..965df869 100644 --- a/exercises/08-Create-a-Basic-HTML/app.py +++ b/exercises/08-Create-a-Basic-HTML/app.py @@ -9,3 +9,5 @@ # DON'T CHANGE THE CODE ABOVE +html_document = e + c + g + a + f + h + d + b +print(html_document) \ No newline at end of file diff --git a/exercises/08-Create-a-Basic-HTML/test.py b/exercises/08-Create-a-Basic-HTML/test.py index 622dde58..eee3ee68 100644 --- a/exercises/08-Create-a-Basic-HTML/test.py +++ b/exercises/08-Create-a-Basic-HTML/test.py @@ -6,6 +6,7 @@ import pytest import app import os +import re @pytest.mark.it('1. Your code needs to print a basic html layout on the console') @@ -16,8 +17,13 @@ def test_for_file_output(capsys): def test_use_my_var1(): f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - content = f.read() - assert content.find("html_document") > 0 + 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]) # @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') # def test_for_function_output(capsys): # my_function() From a9520e7775a6d55bc69a77b0f9353841b09a634d Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 18:32:12 +0000 Subject: [PATCH 69/87] fixed issues 09 --- .../09-Calling-Your-First-Function/test.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/exercises/09-Calling-Your-First-Function/test.py b/exercises/09-Calling-Your-First-Function/test.py index 7430dec3..363aac97 100644 --- a/exercises/09-Calling-Your-First-Function/test.py +++ b/exercises/09-Calling-Your-First-Function/test.py @@ -6,23 +6,25 @@ 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('Print "Hello, --Your Name--"') -def test_desired_output(capsys): - app.is_odd(32345) - captured = capsys.readouterr() - - assert captured.out == "true\n" -@pytest.mark.it("Using the conditional statement") +@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.read() - print("test:",content) - assert content.find("my_number") > 0 + 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" # @pytest.mark.it('Your function needs to print "Hello Inside Function" on the console') # def test_for_function_output(capsys): # my_function() From 5255d84b903543bb752a46d4fec34b73235cbf0e Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 18:59:57 +0000 Subject: [PATCH 70/87] fixed issues 10 --- .../10-Creating-Your-First-Function/app.py | 5 +- .../10-Creating-Your-First-Function/test.py | 53 +++++-------------- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/exercises/10-Creating-Your-First-Function/app.py b/exercises/10-Creating-Your-First-Function/app.py index 12c41273..f4adaf0f 100644 --- a/exercises/10-Creating-Your-First-Function/app.py +++ b/exercises/10-Creating-Your-First-Function/app.py @@ -1,5 +1,6 @@ def add_numbers(a,b): - print(a+b) +# YOUR CODE HERE -add_numbers(3,4) \ No newline at end of file + +print(add_numbers(3,4)) \ No newline at end of file diff --git a/exercises/10-Creating-Your-First-Function/test.py b/exercises/10-Creating-Your-First-Function/test.py index 6c1a5d64..32aca4e5 100644 --- a/exercises/10-Creating-Your-First-Function/test.py +++ b/exercises/10-Creating-Your-First-Function/test.py @@ -8,46 +8,21 @@ import os import re -# @pytest.mark.it('1. You should return the result of a + b ') -# def test_add_number(): -# regex = (r"def add_numbers\(a,b\):\n" -# r" return a\s*\+\s*b") -# # regex = (r"def add_numbers\(a,b\):\n" -# # r" return a\s*\+\s*b") -# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') -# content = f.read() -# print("content", content) -# # matches = re.finditer(regex, content, re.MULTILINE) -# print("matches",regex) +@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 a+b" 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('Add all three numbers') +@pytest.mark.it('2. The console should return 7') def test_add_variables(capsys): - app.add_numbers(3,4) - captured = capsys.readouterr() - print(captured.out) - - if captured.out == str(7) + "\n": - assert True - else: - assert False -# @pytest.mark.it('2. Your code needs to print 7 on the console') -# def test_for_file_output(capsys): -# my_result = 3+4 -# captured = buffer.getvalue() -# assert captured == str(my_result)+"\n" #add \n because the console jumps the line on every print -# @pytest.mark.it('2. You should print on the console the variables_are_cool value ') -# def test_for_file_output(capsys): -# my_result = 2345 *7323 -# captured = buffer.getvalue() -# assert captured == str(my_result)+'\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 + captured = buffer.getvalue() + assert captured == str(7)+"\n" From 211f12806667755f611e5ad859798315b7be8425 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 19:27:36 +0000 Subject: [PATCH 71/87] fixed issues 11 --- exercises/11-Create-A-New-Function/test.py | 48 +++++++++++++++------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/exercises/11-Create-A-New-Function/test.py b/exercises/11-Create-A-New-Function/test.py index 81952f26..32359127 100644 --- a/exercises/11-Create-A-New-Function/test.py +++ b/exercises/11-Create-A-New-Function/test.py @@ -6,25 +6,45 @@ import pytest import os import app +import re -@pytest.mark.it("1. You should create a function called generate_random") -def test_use_my_var1(): - +@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.read() - assert content.find("def generate_random():") > 0 -@pytest.mark.it("2. You should print a random integer inside generate_random function") -def test_use_print(): + 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.read() - assert content.find("print") > 0 -@pytest.mark.it("3. You should call generate_random function correctly") -def test_call_generate_random(): + 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)]) - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - content = f.read() - assert content.find("generate_random()") > 0 # @pytest.mark.it('Your code needs to print hello on the console') # def test_generate_random(capsys): # x = get_generate_random() From 2e0bc067879c2f7af552fc5414c9d379bc398b18 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 19:41:20 +0000 Subject: [PATCH 72/87] fixed issues 12 --- exercises/12-Your-First-If/app.py | 4 +- exercises/12-Your-First-If/test.py | 69 ++++++++++-------------------- 2 files changed, 24 insertions(+), 49 deletions(-) diff --git a/exercises/12-Your-First-If/app.py b/exercises/12-Your-First-If/app.py index 7d097d9d..8180c59c 100644 --- a/exercises/12-Your-First-If/app.py +++ b/exercises/12-Your-First-If/app.py @@ -1,9 +1,9 @@ -total = int(input('How much money do you have in your pocket')) +total = int(input('How much money do you have in your pocket\n')) if (total > 100): print("Give me your money!") elif (total > 50): print("Buy me some coffee you cheap!") elif (total < 51): - print("You are a poor guy, go away!") + print("You are a poor guy, go away!") diff --git a/exercises/12-Your-First-If/test.py b/exercises/12-Your-First-If/test.py index 9634bd34..6ae9497a 100644 --- a/exercises/12-Your-First-If/test.py +++ b/exercises/12-Your-First-If/test.py @@ -1,53 +1,28 @@ # from app import my_function import pytest,os,re,io,sys, mock, json -@pytest.mark.it("1. You should not delete or change the existing code") +@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.pop()): - # f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - sys.stdout = buffer = io.StringIO() - import app - # content = f.readlines() - # regex = r"total = int\(input\('How much money do you have in your pocket\?'\)\)" - # assert re.match(regex, content[0]) - assert "Give me your money!\n" == buffer.getvalue() -# @pytest.mark.it("2. You should not delete or change the existing code") -# def test_e(stdin): -# _input = json.loads(stdin) -# 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 -# # content = f.readlines() -# # regex = r"total = int\(input\('How much money do you have in your pocket\?'\)\)" -# # assert re.match(regex, content[0]) -# assert "Buy me some coffee you cheap!\n" == buffer.getvalue() -# @pytest.mark.it("3. You should not delete or change the existing code") -# def test_w(stdin): -# _input = json.loads(stdin) -# 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 -# # content = f.readlines() -# # regex = r"total = int\(input\('How much money do you have in your pocket\?'\)\)" -# # assert re.match(regex, content[0]) -# assert "You are a poor guy, go away!\n" == buffer.getvalue() - -# @pytest.mark.it('Your code needs to print hello on the console') -# def test_for_file_output(capsys): -# regex = r"print\(random\.rand(\w+)\(10\)\) " -# captured = buffer.getvalue() -# assert captured == regex #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 + 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() + + + + From e0d5a2a090ed86d3e9edcc8b02c98307c00b2df1 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 19:42:36 +0000 Subject: [PATCH 73/87] fixed issues 12 --- exercises/12-Your-First-If/app.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/exercises/12-Your-First-If/app.py b/exercises/12-Your-First-If/app.py index 8180c59c..68b95adf 100644 --- a/exercises/12-Your-First-If/app.py +++ b/exercises/12-Your-First-If/app.py @@ -1,9 +1,4 @@ total = int(input('How much money do you have in your pocket\n')) -if (total > 100): - print("Give me your money!") -elif (total > 50): - print("Buy me some coffee you cheap!") -elif (total < 51): - print("You are a poor guy, go away!") +# YOUR CODE HERE From 1742933573adc17a39fac5cbd9147508efbeb0ef Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 20:06:18 +0000 Subject: [PATCH 74/87] fixed issues 13 --- .../13-How-Much-The-Wedding-Costs/app.py | 22 ++--- .../13-How-Much-The-Wedding-Costs/test.py | 84 +++++++------------ 2 files changed, 37 insertions(+), 69 deletions(-) diff --git a/exercises/13-How-Much-The-Wedding-Costs/app.py b/exercises/13-How-Much-The-Wedding-Costs/app.py index a3d5838e..6550b341 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/app.py +++ b/exercises/13-How-Much-The-Wedding-Costs/app.py @@ -1,15 +1,7 @@ -# user_input = int(input('How many people are coming to your wedding?')) -user_input = 99 -price = 0 -if( user_input < 51): - price = 4000 -elif (51 < user_input and user_input < 101): - price = 10000 -elif (101 < user_input and user_input < 201): - price = 15000 -else: - price = 20000 - - -# Your code above here -print('Your wedding will cost '+str(price)+' dollars'); \ No newline at end of file +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/13-How-Much-The-Wedding-Costs/test.py b/exercises/13-How-Much-The-Wedding-Costs/test.py index d7593ad3..64b25e89 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/test.py +++ b/exercises/13-How-Much-The-Wedding-Costs/test.py @@ -1,55 +1,31 @@ -import io -import sys - # from app import my_function -import pytest -import app -import os -import re - - -@pytest.mark.it("1. You should not delete or change the existing code") -def test_existing_code(): - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - content = f.readlines() - - original_input = r"# user_input = int\(input\('How many people are coming to your wedding\?'\)\)" - assert re.match(original_input, content[0]) - regex = r"print\('Your wedding will cost '\+str\(price\)\+' dollars'\);" - assert re.match(regex, content[(len(content)-1)]) - -@pytest.mark.it("2. You should create a price variable before the if statement") -def test_existingPriceVariable(): - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - content = f.readlines() - content = [x.strip() for x in content] #### With this line of code I removed all the whitespace characters like `\n` at the end of each line - price_variable = r"price = (.+)" - assert re.match(price_variable, content[2]) - # for price in content: - # if price == price_variable: - # assert re.match(price_variable, price) - # for price in content: - # price_index = content.index(price) - # if re.match(price_variable, price_index): - # if price_index < 3: - - - -@pytest.mark.it('3. Your code needs to print the correct outpu on the console') -def test_for_file_output(): - # sys.stdout = buffer = io.StringIO() - test =sys.stdin.read() - # captured = buffer.getvalue() - # print("####",buffer.getvalue()) - print("$$$$",test) - # 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 +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() From ee37430af664b2f595b074567c364a08337497a3 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Wed, 2 Oct 2019 20:45:34 +0000 Subject: [PATCH 75/87] fixed issues 14-15-16 --- exercises/14-Your-First-Switch/app.py | 28 +++++++++------ exercises/15-Random-Numbers/README.md | 4 ++- exercises/15-Random-Numbers/app.py | 3 +- exercises/15-Random-Numbers/test.py | 39 ++++++--------------- exercises/16-Rand-From-One-to-Six/README.md | 7 ++-- exercises/16-Rand-From-One-to-Six/app.py | 2 +- exercises/16-Rand-From-One-to-Six/test.py | 26 +++++++------- 7 files changed, 49 insertions(+), 60 deletions(-) diff --git a/exercises/14-Your-First-Switch/app.py b/exercises/14-Your-First-Switch/app.py index d5ab1210..73b2fc8c 100644 --- a/exercises/14-Your-First-Switch/app.py +++ b/exercises/14-Your-First-Switch/app.py @@ -1,14 +1,20 @@ -def getColor(selection): +def get_color(color_name): - switch(selection){ - //Add more options here - default : - return false;//return false because the user pick a unavailable color - break + switcher = { + 0:'Red', + 1:'red', + 2:'blue', + 3:'Blue', + 4:'green', + 5:'Green' + } + return switcher.get(color_name,"Invalid day of week") - -var colorname = window.prompt('What color do you want?'); -var isAvailable = getColor(colorname); -if(isAvailable) console.log('Good news! That color is available'); -else console.log('We are sorry, that color is not available'); \ No newline at end of file +color_input= str(input('What color do you want?\n')) +#print("$$$",get_color(color_input) +is_available = get_color(color_input) +if(is_available): + print('Good news! That color is available') +else: + print('We are sorry, that color is not available') \ No newline at end of file diff --git a/exercises/15-Random-Numbers/README.md b/exercises/15-Random-Numbers/README.md index b9b382da..83ea51bf 100644 --- a/exercises/15-Random-Numbers/README.md +++ b/exercises/15-Random-Numbers/README.md @@ -1,8 +1,10 @@ # `15` Random Numbers -You can use the **randint()** function to get a random decimal number. **randint()** is an inbuilt function of the random module in Python3. +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/15-Random-Numbers/app.py b/exercises/15-Random-Numbers/app.py index 2cfa94f5..aeefd3f7 100644 --- a/exercises/15-Random-Numbers/app.py +++ b/exercises/15-Random-Numbers/app.py @@ -1,7 +1,8 @@ import random def get_randomInt(): - random_number = random.randrange(10) + # CHANGE ONLY THIS LINE BELOW + random_number = random.random() return random_number diff --git a/exercises/15-Random-Numbers/test.py b/exercises/15-Random-Numbers/test.py index 78f0d31a..a0f9fb40 100644 --- a/exercises/15-Random-Numbers/test.py +++ b/exercises/15-Random-Numbers/test.py @@ -4,35 +4,16 @@ # from app import my_function import pytest +import os +import re -@pytest.mark.it("1. You should not delete or change the existing code") -def test_existing_code(): - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') +@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]) - original_input = r"# user_input = int\(input\('How many people are coming to your wedding\?'\)\)" - assert re.match(original_input, content[0]) - regex = r"print\('Your wedding will cost '\+str\(price\)\+' dollars'\);" - assert re.match(regex, content[(len(content)-1)]) - -@pytest.mark.it("2. You should create a price variable before the if statement") -def test_existingPriceVariable(): - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - content = f.readlines() - content = [x.strip() for x in content] #### With this line of code I removed all the whitespace characters like `\n` at the end of each line - price_variable = r"price = (.+)" - assert re.match(price_variable, content[2]) -@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('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/16-Rand-From-One-to-Six/README.md b/exercises/16-Rand-From-One-to-Six/README.md index e23f32d6..d133fb5f 100644 --- a/exercises/16-Rand-From-One-to-Six/README.md +++ b/exercises/16-Rand-From-One-to-Six/README.md @@ -1,13 +1,14 @@ -# `16` Rand From 1 to 6 +# `16` 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 6. +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 6, not between 0 and 6. +- 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/16-Rand-From-One-to-Six/app.py b/exercises/16-Rand-From-One-to-Six/app.py index 4958e622..0e29fa95 100644 --- a/exercises/16-Rand-From-One-to-Six/app.py +++ b/exercises/16-Rand-From-One-to-Six/app.py @@ -1,7 +1,7 @@ import random def get_randomInt(): - random_number = random.randrange(7) + random_number = random.randint(1,10) return random_number diff --git a/exercises/16-Rand-From-One-to-Six/test.py b/exercises/16-Rand-From-One-to-Six/test.py index 0d6ad4d0..92b35a92 100644 --- a/exercises/16-Rand-From-One-to-Six/test.py +++ b/exercises/16-Rand-From-One-to-Six/test.py @@ -4,18 +4,16 @@ # from app import my_function import pytest +import os +import app +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('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 +@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]) From 38d4e0ee908024fa85dd2cb23403d5fa65f78a30 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 4 Oct 2019 14:50:32 +0000 Subject: [PATCH 76/87] fixed issues 17-18-19 --- exercises/17-Your-First-Loop/test.py | 41 +++++-------------- exercises/18-Create-A-For-Loop/README.md | 4 +- exercises/18-Create-A-For-Loop/app.py | 4 -- exercises/18-Create-A-For-Loop/test.py | 50 ++++++++++++++++++------ exercises/19-While-Loop/README.md | 5 +++ exercises/19-While-Loop/app.py | 7 ++++ exercises/19-While-Loop/test.py | 36 ++++++++++------- 7 files changed, 84 insertions(+), 63 deletions(-) diff --git a/exercises/17-Your-First-Loop/test.py b/exercises/17-Your-First-Loop/test.py index af3016dc..8e301955 100644 --- a/exercises/17-Your-First-Loop/test.py +++ b/exercises/17-Your-First-Loop/test.py @@ -9,35 +9,12 @@ import re -@pytest.mark.it("1. You should fix the existing code") -def test_existingCode(): - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - content = f.read() - # content = [x.strip() for x in content] #### With this line of code I removed all the whitespace characters like `\n` at the end of each line - # print("$$$$", content) - price_variable = (r"def start_counting\(\): \n" - r"(\s*)for i in range\(101\):\n" - r"(\s*)print\(i\) \n" - r"(\s+)return i\n\n" - r"start_counting\(\)") - assert re.match(price_variable, content) - -# @pytest.mark.it('The console should count from 0 to 100') -# def test_for_file_output(capsys): -# def start_counting(): -# for i in range(101): -# print(i) - -# captured = buffer.getvalue() -# print("test",start_counting()) -# assert captured == str(start_counting())+'\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 +@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/18-Create-A-For-Loop/README.md b/exercises/18-Create-A-For-Loop/README.md index 17393992..0bcee6b0 100644 --- a/exercises/18-Create-A-For-Loop/README.md +++ b/exercises/18-Create-A-For-Loop/README.md @@ -11,7 +11,9 @@ https://www.w3schools.com/python/python_for_loops.asp ## πŸ“ Instructions: -1. Create a function called **standards_maker** that prints 300 times the phrase "I will write questions if I'm stuck". +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: diff --git a/exercises/18-Create-A-For-Loop/app.py b/exercises/18-Create-A-For-Loop/app.py index b2c06d24..e69de29b 100644 --- a/exercises/18-Create-A-For-Loop/app.py +++ b/exercises/18-Create-A-For-Loop/app.py @@ -1,4 +0,0 @@ -def standard_maker(): - for x in range(300): - print("I will write questions if I'm stuck") -standard_maker() \ No newline at end of file diff --git a/exercises/18-Create-A-For-Loop/test.py b/exercises/18-Create-A-For-Loop/test.py index 0d6ad4d0..d7f8eff5 100644 --- a/exercises/18-Create-A-For-Loop/test.py +++ b/exercises/18-Create-A-For-Loop/test.py @@ -4,18 +4,44 @@ # from app import my_function import pytest +import os +import app +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 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('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("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\"\)" -# @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 + 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/19-While-Loop/README.md b/exercises/19-While-Loop/README.md index 56dd9720..2cb7d33a 100644 --- a/exercises/19-While-Loop/README.md +++ b/exercises/19-While-Loop/README.md @@ -4,4 +4,9 @@ This code is broken, it produces an infinite loop. Replit handles the infinite l Fix the problem, to print from 100 - 0. And return 0. +## πŸ’‘ Hint: + +- To stop the infinite loop press **ctrl + c** 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/19-While-Loop/app.py b/exercises/19-While-Loop/app.py index e69de29b..84b0e9db 100644 --- a/exercises/19-While-Loop/app.py +++ b/exercises/19-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/19-While-Loop/test.py b/exercises/19-While-Loop/test.py index 0d6ad4d0..c205ff23 100644 --- a/exercises/19-While-Loop/test.py +++ b/exercises/19-While-Loop/test.py @@ -4,18 +4,26 @@ # 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('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('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 +# @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 From 0fb467bd505be881e6f2e9ff9a19cde9eeb3b87d Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 4 Oct 2019 15:30:15 +0000 Subject: [PATCH 77/87] fixed issues 21 --- exercises/21-Looping-With-FizzBuzz/app.py | 14 ++------- exercises/21-Looping-With-FizzBuzz/test.py | 34 +++++++++++----------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/exercises/21-Looping-With-FizzBuzz/app.py b/exercises/21-Looping-With-FizzBuzz/app.py index 7a0c1c6a..daab9805 100644 --- a/exercises/21-Looping-With-FizzBuzz/app.py +++ b/exercises/21-Looping-With-FizzBuzz/app.py @@ -1,15 +1,5 @@ - -# print('\n'.join("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i) for i in range(1,101))) def fizz_buzz(): # your code here - for i in range(1,101): - if(i % 3 == 0 and i % 5 == 0): - print("FizzBuzz") - elif(i % 3 == 0): - print("Fizz") - elif(i % 5 == 0): - print("Buzz") - else: - print(i) - + + fizz_buzz() \ No newline at end of file diff --git a/exercises/21-Looping-With-FizzBuzz/test.py b/exercises/21-Looping-With-FizzBuzz/test.py index be66a339..e6b90445 100644 --- a/exercises/21-Looping-With-FizzBuzz/test.py +++ b/exercises/21-Looping-With-FizzBuzz/test.py @@ -1,29 +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('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') +@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] - print("@@@@", content) - regex = r"fizz_buzz\(\)" - 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" + 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\(\)" -# @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 + 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" From f51d6be0deef4af8086b1c3ccc5398161023d280 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 4 Oct 2019 16:32:36 +0000 Subject: [PATCH 78/87] fixed issues 22 --- exercises/22-Russian-Roulette/README.md | 4 ++-- exercises/22-Russian-Roulette/app.py | 9 +++------ exercises/22-Russian-Roulette/test.py | 19 ++++++------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/exercises/22-Russian-Roulette/README.md b/exercises/22-Russian-Roulette/README.md index 5084b1fc..fe145888 100644 --- a/exercises/22-Russian-Roulette/README.md +++ b/exercises/22-Russian-Roulette/README.md @@ -15,5 +15,5 @@ FIRE!!!....... are you dead? ## πŸ’‘ Hint: -- The function needs to return **true** or **false** depending on the result, if the bullet was -at the same slot as the revolver chamber, then it will be fired (**false**). +- 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/22-Russian-Roulette/app.py b/exercises/22-Russian-Roulette/app.py index d9c3b432..664d81ed 100644 --- a/exercises/22-Russian-Roulette/app.py +++ b/exercises/22-Russian-Roulette/app.py @@ -6,13 +6,10 @@ def spin_chamber(): chamber_position = random.randint(1,6) return chamber_position - +# DON'T CHANGE THE CODE ABOVE def fire_gun(): - #you code here - if(spin_chamber() == bullet_position): - return 'Keep playing :)' - else: - return 'You are dead!' + # YOUR CODE HERE + diff --git a/exercises/22-Russian-Roulette/test.py b/exercises/22-Russian-Roulette/test.py index 92e43e4a..35ddd0ea 100644 --- a/exercises/22-Russian-Roulette/test.py +++ b/exercises/22-Russian-Roulette/test.py @@ -8,22 +8,15 @@ import re import os -@pytest.mark.it('STEP 1. Your code needs to print the correct output on the console') + +@pytest.mark.it('1. 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) + 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[(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" + assert re.match(regex, content[my_codeCallVar]) -# @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 From f980101b562075420bb1f3f0cf264fdad9610ce0 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Fri, 4 Oct 2019 16:32:59 +0000 Subject: [PATCH 79/87] fixed issues 23 --- exercises/23-The-Beatles/README.md | 18 +++++++++++++--- exercises/23-The-Beatles/app.py | 16 +++++--------- exercises/23-The-Beatles/test.py | 34 ++++++++++++++++-------------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/exercises/23-The-Beatles/README.md b/exercises/23-The-Beatles/README.md index 8aa7eb50..f4c2c05b 100644 --- a/exercises/23-The-Beatles/README.md +++ b/exercises/23-The-Beatles/README.md @@ -10,10 +10,22 @@ This is the chorus of one of the most famous Beatle songs: > Let it be ## πŸ“ Instructions: -1. Create and function called **sing** that 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: +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: -let it be, let it be, let it be, let it be, 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 +```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: diff --git a/exercises/23-The-Beatles/app.py b/exercises/23-The-Beatles/app.py index 8f3437a7..0baf074f 100644 --- a/exercises/23-The-Beatles/app.py +++ b/exercises/23-The-Beatles/app.py @@ -1,12 +1,6 @@ # Your code here!! -def sing(): - - repeated_text = "" - final_string = "" - for i in range(1,5): - repeated_text += "let it be, \n" - final_string = repeated_text + "Whisper words of wisdom, let it be, " + repeated_text + "there will be an answer, " + "let it be" - return final_string - - -print(sing()) \ No newline at end of file + + + + + diff --git a/exercises/23-The-Beatles/test.py b/exercises/23-The-Beatles/test.py index b9649961..66e1f46f 100644 --- a/exercises/23-The-Beatles/test.py +++ b/exercises/23-The-Beatles/test.py @@ -1,28 +1,30 @@ import io import sys sys.stdout = buffer = io.StringIO() +from app import sing -# from app import my_function import pytest import os import app 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') + +@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] - print("@@@@", content) - regex = r"print\(sing\(\)\)" - 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" + 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('Your function needs to return True') -# def test_for_function_return(capsys): -# assert my_function() == True \ No newline at end of file +@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 From e29047ea8764a9ed070b95edac823a64ea7609c7 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Sat, 5 Oct 2019 02:03:59 +0000 Subject: [PATCH 80/87] fixed issues 24 - 25 --- exercises/24-Bottles-Of-Milk/README.md | 5 +- exercises/24-Bottles-Of-Milk/app.py | 20 --- exercises/24-Bottles-Of-Milk/test.py | 230 ++++++++++++++++++++++++- exercises/25-Python-Objects/README.md | 3 +- exercises/25-Python-Objects/app.py | 45 ++--- exercises/25-Python-Objects/test.py | 49 +++--- 6 files changed, 271 insertions(+), 81 deletions(-) diff --git a/exercises/24-Bottles-Of-Milk/README.md b/exercises/24-Bottles-Of-Milk/README.md index 3ff8c5b8..600d353f 100644 --- a/exercises/24-Bottles-Of-Milk/README.md +++ b/exercises/24-Bottles-Of-Milk/README.md @@ -5,10 +5,9 @@ here you can here it: https://www.youtube.com/watch?v=Xy-da43E6Lo ## πŸ“ Instructions: -1. Please write an algorithm to print the exact same lyrics. +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. -let it be, let it be, let it be, let it be, 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: diff --git a/exercises/24-Bottles-Of-Milk/app.py b/exercises/24-Bottles-Of-Milk/app.py index d54ef86d..e69de29b 100644 --- a/exercises/24-Bottles-Of-Milk/app.py +++ b/exercises/24-Bottles-Of-Milk/app.py @@ -1,20 +0,0 @@ -def number_of_bottles(): - plural_line = "" - second_line = "" - sing_line = "" - last_line = "" - for i in range(100,0,-1): - - if i>2: - plural_line += str(i) + " bottles of milk on the wall, " + str(i) + " bottles of milk."+ "\n" + "Take one down and pass it around, " + str(i-1) + " bottles of milk on the wall."+ "\n" - elif i == 2: - second_line += str(i) + " bottles of milk on the wall, " + str(i) + " bottles of milk."+ "\n" + "Take one down and pass it around, " + str(i-1) +" bottle of milk on the wall."+ "\n" - elif i == 1: - sing_line += str(i) + " bottle of milk on the wall, " + str(i) + " bottle of milk."+ "\n" + "Take one down and pass it around, " + "no more bottles of milk on the wall."+ "\n" - else: - last_line = "No more bottles of milk on the wall, no more bottles of milk." +"\n"+"Go to the store and buy some more, "+ str(i+99) +" bottles of milk on the wall." - - return plural_line + second_line + sing_line + last_line - - -print(number_of_bottles()) \ No newline at end of file diff --git a/exercises/24-Bottles-Of-Milk/test.py b/exercises/24-Bottles-Of-Milk/test.py index e2e3a9bd..8bbbff10 100644 --- a/exercises/24-Bottles-Of-Milk/test.py +++ b/exercises/24-Bottles-Of-Milk/test.py @@ -1,22 +1,238 @@ 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('STEP 3. Your code needs to print the correct output on the console') +@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): - 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\(number_of_bottles\(\)\)" - assert re.match(regex, content[(len(content)-1)]) + 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() diff --git a/exercises/25-Python-Objects/README.md b/exercises/25-Python-Objects/README.md index 95864407..8a860aff 100644 --- a/exercises/25-Python-Objects/README.md +++ b/exercises/25-Python-Objects/README.md @@ -77,6 +77,7 @@ 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** Now please print ( console.log() ) the SUM of all of the lucky numbers of the Doe family. +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/25-Python-Objects/app.py b/exercises/25-Python-Objects/app.py index 7ba3d36f..3b765a8c 100644 --- a/exercises/25-Python-Objects/app.py +++ b/exercises/25-Python-Objects/app.py @@ -1,14 +1,14 @@ class Person: - name = "John" + name = "John" lastname = "Doe" - age = 35 + age = 35 gender = "male" - lucky_numbers = [ 7, 11, 13, 17] - + lucky_numbers = [ 7, 11, 13, 17] + class Person_2: - name = "Jane" - lastname = "Doe" + name = "Jane" + lastname = "Doe" age = 38 gender = "female" lucky_numbers = [ 2, 4, 6, 8] @@ -17,34 +17,25 @@ 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 + +# STEP 1 Change the fourth lucky number of John Doe to 33 # Your code here -Person.lucky_numbers[3] = 33 + # STEP 2 Create Little Jimmy's object and then add it to the family object # Your code here - -class Person_3: - name = "Jimmy" - lastname = "Doe" - age = 13 - gender = "female" - lucky_numbers = [ 1, 2, 3, 4] - -Family.members.append(Person_3) + + def add_allFamilyLuckyNumbers(an_array): sum_ofAllLuckyNumbers = 0 # sum_ofAllLuckyNumbers is a number, the sum of all lucky numbers. - temp = 0 - for i in Family.members: - for x in i.lucky_numbers: - sum_ofAllLuckyNumbers += x - - return sum_ofAllLuckyNumbers - -# STEP 3 Print the sum of all the lucky numbers of the Doe's family + + # 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 -print(add_allFamilyLuckyNumbers(Family.members)) \ No newline at end of file diff --git a/exercises/25-Python-Objects/test.py b/exercises/25-Python-Objects/test.py index ef7804ff..05f01659 100644 --- a/exercises/25-Python-Objects/test.py +++ b/exercises/25-Python-Objects/test.py @@ -8,38 +8,41 @@ import os import re -@pytest.mark.it("1. You should not delete or change the existing code") -def test_existing_code(): - f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') - content = f.readlines() - content = [x.strip() for x in content] - print("@@@@",content) - - original_input = [ - r"class Person:", - r"(\s*)name = \"John\"", - r"(\s*)lastname = \"Doe\"", - r"(\s*)age = 35", - r"(\s*)gender = \"male\"", - r"(\s*)lucky_numbers = \[ 7, 11, 13, 17]" - ] - print("$$$$$$",[i for i, j in zip(original_input, content) if i == j ]) - # regex = r"print\('Your wedding will cost '\+str\(price\)\+' dollars'\);" - # assert re.match(regex, content[(len(content)-1)]) - +@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('STEP 3. Your code needs to print the correct sum on the console') +@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] - print("@@@@", content) - regex = r"print\(add_allFamilyLuckyNumbers\(Family\.members\)\) " - assert re.match(regex, content[(len(content)-1)]) + 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') From 537d4e756b4c3f0d7e3cd4a555cf2b441df78db4 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Sat, 5 Oct 2019 19:37:48 +0000 Subject: [PATCH 81/87] fixed issues 01 - 02 --- exercises/01-Console/README.md | 2 +- exercises/01-Console/app.py | 2 +- exercises/01-Console/test.py | 11 ++++++++++- exercises/02-Declare-Variables/app.py | 2 -- exercises/02-Declare-Variables/test.py | 13 +++++++++++++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/exercises/01-Console/README.md b/exercises/01-Console/README.md index fdb43bd7..5c6b3398 100644 --- a/exercises/01-Console/README.md +++ b/exercises/01-Console/README.md @@ -12,5 +12,5 @@ print("How are you?") ## πŸ“ Instructions: -Use **print** to print "Hello World" on the console. Feel free to try other things as well. +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 index f301245e..8b137891 100644 --- a/exercises/01-Console/app.py +++ b/exercises/01-Console/app.py @@ -1 +1 @@ -print("Hello World!") + diff --git a/exercises/01-Console/test.py b/exercises/01-Console/test.py index cd70af90..d2f519b9 100644 --- a/exercises/01-Console/test.py +++ b/exercises/01-Console/test.py @@ -2,11 +2,20 @@ 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/02-Declare-Variables/app.py b/exercises/02-Declare-Variables/app.py index 00be7bf1..e69de29b 100644 --- a/exercises/02-Declare-Variables/app.py +++ b/exercises/02-Declare-Variables/app.py @@ -1,2 +0,0 @@ -name = "Yellow" -print(name) \ No newline at end of file diff --git a/exercises/02-Declare-Variables/test.py b/exercises/02-Declare-Variables/test.py index 9ba4957f..607dd8b4 100644 --- a/exercises/02-Declare-Variables/test.py +++ b/exercises/02-Declare-Variables/test.py @@ -19,6 +19,19 @@ @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 From 9dc7c9b48529f85168670b31e7541f3318e2e27c Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Mon, 7 Oct 2019 01:17:34 +0000 Subject: [PATCH 82/87] fixed issues 03 --- exercises/03-Print-Variables-In-The-Console/README.md | 2 +- exercises/03-Print-Variables-In-The-Console/app.py | 2 -- exercises/03-Print-Variables-In-The-Console/test.py | 8 ++++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/exercises/03-Print-Variables-In-The-Console/README.md b/exercises/03-Print-Variables-In-The-Console/README.md index c365d25a..fafe9401 100644 --- a/exercises/03-Print-Variables-In-The-Console/README.md +++ b/exercises/03-Print-Variables-In-The-Console/README.md @@ -8,6 +8,6 @@ print(my_super_variable) ## πŸ“ Instructions: -1. Declare a new variable called color and assign the value "red" to it. +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 index 04b067d9..e69de29b 100644 --- a/exercises/03-Print-Variables-In-The-Console/app.py +++ b/exercises/03-Print-Variables-In-The-Console/app.py @@ -1,2 +0,0 @@ -color = "red" -print(color) diff --git a/exercises/03-Print-Variables-In-The-Console/test.py b/exercises/03-Print-Variables-In-The-Console/test.py index 3f9859ea..6134039c 100644 --- a/exercises/03-Print-Variables-In-The-Console/test.py +++ b/exercises/03-Print-Variables-In-The-Console/test.py @@ -20,6 +20,14 @@ def test_use_forLoop(): 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') From c9b5dc2d9c9690dc4cef8bd578b85300fa7537a7 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Mon, 7 Oct 2019 01:25:13 +0000 Subject: [PATCH 83/87] fixed issues 04 --- exercises/04-Multiply-Two-Values/app.py | 2 -- exercises/04-Multiply-Two-Values/test.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/exercises/04-Multiply-Two-Values/app.py b/exercises/04-Multiply-Two-Values/app.py index b8b6971b..e69de29b 100644 --- a/exercises/04-Multiply-Two-Values/app.py +++ b/exercises/04-Multiply-Two-Values/app.py @@ -1,2 +0,0 @@ -variables_are_cool = 2345 * 7323 -print(variables_are_cool) \ No newline at end of file diff --git a/exercises/04-Multiply-Two-Values/test.py b/exercises/04-Multiply-Two-Values/test.py index ea84ce4e..5b9ca806 100644 --- a/exercises/04-Multiply-Two-Values/test.py +++ b/exercises/04-Multiply-Two-Values/test.py @@ -20,7 +20,7 @@ def test_use_variable_name(): @pytest.mark.it('2. You should print on the console the variables_are_cool value ') def test_for_file_output(capsys): - regex = r"print\(variables_are_cool\)" + 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] From 1fa2128c7919217a56b8ff240f08cd0eb19b2aef Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Mon, 7 Oct 2019 01:39:50 +0000 Subject: [PATCH 84/87] fixed issues 05 --- exercises/05-User-Inputed-Values/README.md | 3 ++- exercises/05-User-Inputed-Values/app.py | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/05-User-Inputed-Values/README.md b/exercises/05-User-Inputed-Values/README.md index d8037f8c..5fc6cba4 100644 --- a/exercises/05-User-Inputed-Values/README.md +++ b/exercises/05-User-Inputed-Values/README.md @@ -7,6 +7,7 @@ For example, the application right now is prompting the user for its age, and th ## πŸ“ 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. + +- 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 index 971faa7b..42b66228 100644 --- a/exercises/05-User-Inputed-Values/app.py +++ b/exercises/05-User-Inputed-Values/app.py @@ -1,5 +1,4 @@ -age = int(input('What is your age?')) -# YOUR CODE HERE +age = int(input('What is your age?\n')) +# CHANGE THE CODE BELOW TO ADD 10 TO AGE -print("Your age is: "+str(int(age)+10)) -# print(age+10) \ No newline at end of file +print("Your age is: "+str(age)) From 187af9fcba82bda07fbb6becae405c41419ba592 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Mon, 7 Oct 2019 01:40:46 +0000 Subject: [PATCH 85/87] deleted constant exercise --- exercises/06-Constants/README.md | 21 --------------------- exercises/06-Constants/app.py | 5 ----- exercises/06-Constants/test.py | 21 --------------------- 3 files changed, 47 deletions(-) delete mode 100644 exercises/06-Constants/README.md delete mode 100644 exercises/06-Constants/app.py delete mode 100644 exercises/06-Constants/test.py diff --git a/exercises/06-Constants/README.md b/exercises/06-Constants/README.md deleted file mode 100644 index 681f66be..00000000 --- a/exercises/06-Constants/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# `06` Constants - -Since 2015, Javascript also allows the usage of constants, they differ from variables because once declared, they cannot change their value over time like variables can. - -To declare a constant, you have to use the reserved word **const** instead of **var**, like this: - -```py -VERSION = '1.2' -``` - -Constants are super useful because some times, as a developer, you want to make sure parts of your data are read-only. - - -## πŸ“ Instructions: - -1. Run the exercise and fix the error that will show on the console. -2. Make the code output **0.9** on the console when fixed. - -## πŸ’‘ Hint: - -Search the error on google.com to learn how to fix it. \ No newline at end of file diff --git a/exercises/06-Constants/app.py b/exercises/06-Constants/app.py deleted file mode 100644 index c0356891..00000000 --- a/exercises/06-Constants/app.py +++ /dev/null @@ -1,5 +0,0 @@ -VERSION = '0.1'; - -VERSION = '0.9'; - -print(VERSION); \ No newline at end of file diff --git a/exercises/06-Constants/test.py b/exercises/06-Constants/test.py deleted file mode 100644 index 0d6ad4d0..00000000 --- a/exercises/06-Constants/test.py +++ /dev/null @@ -1,21 +0,0 @@ -import io -import sys -sys.stdout = buffer = io.StringIO() - -# from app import my_function -import pytest - -@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('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 From 8500ea03ea565079d9e448d7f77140f6fb69c3ac Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Mon, 7 Oct 2019 02:29:55 +0000 Subject: [PATCH 86/87] fixed genaral issues --- .../README.md | 2 +- .../app.py | 0 .../test.py | 23 ++++++-- .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 exercises/14-Your-First-Switch/README.md | 36 ------------ exercises/14-Your-First-Switch/app.py | 20 ------- exercises/14-Your-First-Switch/test.py | 21 ------- .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../{19-While-Loop => 17-While-Loop}/app.py | 0 .../{19-While-Loop => 17-While-Loop}/test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 2 +- .../{23-The-Beatles => 21-The-Beatles}/app.py | 0 .../test.py | 0 .../README.md | 2 +- .../app.py | 0 .../test.py | 0 .../README.md | 58 +++++++++---------- .../app.py | 0 .../test.py | 0 57 files changed, 61 insertions(+), 131 deletions(-) rename exercises/{07-String-Concatenation => 06-String-Concatenation}/README.md (94%) rename exercises/{07-String-Concatenation => 06-String-Concatenation}/app.py (100%) rename exercises/{07-String-Concatenation => 06-String-Concatenation}/test.py (59%) rename exercises/{08-Create-a-Basic-HTML => 07-Create-a-Basic-HTML}/README.md (95%) rename exercises/{08-Create-a-Basic-HTML => 07-Create-a-Basic-HTML}/app.py (100%) rename exercises/{08-Create-a-Basic-HTML => 07-Create-a-Basic-HTML}/test.py (100%) rename exercises/{09-Calling-Your-First-Function => 08-Calling-Your-First-Function}/README.md (93%) rename exercises/{09-Calling-Your-First-Function => 08-Calling-Your-First-Function}/app.py (100%) rename exercises/{09-Calling-Your-First-Function => 08-Calling-Your-First-Function}/test.py (100%) rename exercises/{10-Creating-Your-First-Function => 09-Creating-Your-First-Function}/README.md (95%) rename exercises/{10-Creating-Your-First-Function => 09-Creating-Your-First-Function}/app.py (100%) rename exercises/{10-Creating-Your-First-Function => 09-Creating-Your-First-Function}/test.py (100%) rename exercises/{11-Create-A-New-Function => 10-Create-A-New-Function}/README.md (97%) rename exercises/{11-Create-A-New-Function => 10-Create-A-New-Function}/app.py (100%) rename exercises/{11-Create-A-New-Function => 10-Create-A-New-Function}/test.py (100%) rename exercises/{12-Your-First-If => 11-Your-First-If}/README.md (95%) rename exercises/{12-Your-First-If => 11-Your-First-If}/app.py (100%) rename exercises/{12-Your-First-If => 11-Your-First-If}/test.py (100%) rename exercises/{13-How-Much-The-Wedding-Costs => 12-How-Much-The-Wedding-Costs}/README.md (93%) rename exercises/{13-How-Much-The-Wedding-Costs => 12-How-Much-The-Wedding-Costs}/app.py (100%) rename exercises/{13-How-Much-The-Wedding-Costs => 12-How-Much-The-Wedding-Costs}/test.py (100%) rename exercises/{15-Random-Numbers => 13-Random-Numbers}/README.md (95%) rename exercises/{15-Random-Numbers => 13-Random-Numbers}/app.py (100%) rename exercises/{15-Random-Numbers => 13-Random-Numbers}/test.py (100%) rename exercises/{16-Rand-From-One-to-Six => 14-Rand-From-One-to-Six}/README.md (92%) rename exercises/{16-Rand-From-One-to-Six => 14-Rand-From-One-to-Six}/app.py (100%) rename exercises/{16-Rand-From-One-to-Six => 14-Rand-From-One-to-Six}/test.py (100%) delete mode 100644 exercises/14-Your-First-Switch/README.md delete mode 100644 exercises/14-Your-First-Switch/app.py delete mode 100644 exercises/14-Your-First-Switch/test.py rename exercises/{17-Your-First-Loop => 15-Your-First-Loop}/README.md (93%) rename exercises/{17-Your-First-Loop => 15-Your-First-Loop}/app.py (100%) rename exercises/{17-Your-First-Loop => 15-Your-First-Loop}/test.py (100%) rename exercises/{18-Create-A-For-Loop => 16-Create-A-For-Loop}/README.md (95%) rename exercises/{18-Create-A-For-Loop => 16-Create-A-For-Loop}/app.py (100%) rename exercises/{18-Create-A-For-Loop => 16-Create-A-For-Loop}/test.py (100%) rename exercises/{19-While-Loop => 17-While-Loop}/README.md (95%) rename exercises/{19-While-Loop => 17-While-Loop}/app.py (100%) rename exercises/{19-While-Loop => 17-While-Loop}/test.py (100%) rename exercises/{20-Random-Colors-Loop => 18-Random-Colors-Loop}/README.md (96%) rename exercises/{20-Random-Colors-Loop => 18-Random-Colors-Loop}/app.py (100%) rename exercises/{20-Random-Colors-Loop => 18-Random-Colors-Loop}/test.py (100%) rename exercises/{21-Looping-With-FizzBuzz => 19-Looping-With-FizzBuzz}/README.md (95%) rename exercises/{21-Looping-With-FizzBuzz => 19-Looping-With-FizzBuzz}/app.py (100%) rename exercises/{21-Looping-With-FizzBuzz => 19-Looping-With-FizzBuzz}/test.py (100%) rename exercises/{22-Russian-Roulette => 20-Russian-Roulette}/README.md (96%) rename exercises/{22-Russian-Roulette => 20-Russian-Roulette}/app.py (100%) rename exercises/{22-Russian-Roulette => 20-Russian-Roulette}/test.py (100%) rename exercises/{23-The-Beatles => 21-The-Beatles}/README.md (97%) rename exercises/{23-The-Beatles => 21-The-Beatles}/app.py (100%) rename exercises/{23-The-Beatles => 21-The-Beatles}/test.py (100%) rename exercises/{24-Bottles-Of-Milk => 22-Bottles-Of-Milk}/README.md (97%) rename exercises/{24-Bottles-Of-Milk => 22-Bottles-Of-Milk}/app.py (100%) rename exercises/{24-Bottles-Of-Milk => 22-Bottles-Of-Milk}/test.py (100%) rename exercises/{25-Python-Objects => 23-Python-Objects}/README.md (67%) rename exercises/{25-Python-Objects => 23-Python-Objects}/app.py (100%) rename exercises/{25-Python-Objects => 23-Python-Objects}/test.py (100%) diff --git a/exercises/07-String-Concatenation/README.md b/exercises/06-String-Concatenation/README.md similarity index 94% rename from exercises/07-String-Concatenation/README.md rename to exercises/06-String-Concatenation/README.md index 8105bd6b..a730711f 100644 --- a/exercises/07-String-Concatenation/README.md +++ b/exercises/06-String-Concatenation/README.md @@ -1,4 +1,4 @@ -# `07` String Concatenation +# `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. diff --git a/exercises/07-String-Concatenation/app.py b/exercises/06-String-Concatenation/app.py similarity index 100% rename from exercises/07-String-Concatenation/app.py rename to exercises/06-String-Concatenation/app.py diff --git a/exercises/07-String-Concatenation/test.py b/exercises/06-String-Concatenation/test.py similarity index 59% rename from exercises/07-String-Concatenation/test.py rename to exercises/06-String-Concatenation/test.py index a3a37b2c..4d7e6534 100644 --- a/exercises/07-String-Concatenation/test.py +++ b/exercises/06-String-Concatenation/test.py @@ -6,20 +6,31 @@ 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.read() - assert content.find("my_var1") > 0 + 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.read() - assert content.find("my_var2") > 0 + 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): diff --git a/exercises/08-Create-a-Basic-HTML/README.md b/exercises/07-Create-a-Basic-HTML/README.md similarity index 95% rename from exercises/08-Create-a-Basic-HTML/README.md rename to exercises/07-Create-a-Basic-HTML/README.md index 6e4b683e..2e978814 100644 --- a/exercises/08-Create-a-Basic-HTML/README.md +++ b/exercises/07-Create-a-Basic-HTML/README.md @@ -1,4 +1,4 @@ -# `08` Create a basic HTML +# `07` Create a basic HTML Let's continue using string concatenation to generate HTML... diff --git a/exercises/08-Create-a-Basic-HTML/app.py b/exercises/07-Create-a-Basic-HTML/app.py similarity index 100% rename from exercises/08-Create-a-Basic-HTML/app.py rename to exercises/07-Create-a-Basic-HTML/app.py diff --git a/exercises/08-Create-a-Basic-HTML/test.py b/exercises/07-Create-a-Basic-HTML/test.py similarity index 100% rename from exercises/08-Create-a-Basic-HTML/test.py rename to exercises/07-Create-a-Basic-HTML/test.py diff --git a/exercises/09-Calling-Your-First-Function/README.md b/exercises/08-Calling-Your-First-Function/README.md similarity index 93% rename from exercises/09-Calling-Your-First-Function/README.md rename to exercises/08-Calling-Your-First-Function/README.md index 58942f63..b4d9990a 100644 --- a/exercises/09-Calling-Your-First-Function/README.md +++ b/exercises/08-Calling-Your-First-Function/README.md @@ -1,4 +1,4 @@ -# `09` Calling Your First Function +# `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. diff --git a/exercises/09-Calling-Your-First-Function/app.py b/exercises/08-Calling-Your-First-Function/app.py similarity index 100% rename from exercises/09-Calling-Your-First-Function/app.py rename to exercises/08-Calling-Your-First-Function/app.py diff --git a/exercises/09-Calling-Your-First-Function/test.py b/exercises/08-Calling-Your-First-Function/test.py similarity index 100% rename from exercises/09-Calling-Your-First-Function/test.py rename to exercises/08-Calling-Your-First-Function/test.py diff --git a/exercises/10-Creating-Your-First-Function/README.md b/exercises/09-Creating-Your-First-Function/README.md similarity index 95% rename from exercises/10-Creating-Your-First-Function/README.md rename to exercises/09-Creating-Your-First-Function/README.md index f1953dde..8e925b33 100644 --- a/exercises/10-Creating-Your-First-Function/README.md +++ b/exercises/09-Creating-Your-First-Function/README.md @@ -1,4 +1,4 @@ -# `10` Creating Your First Function +# `09` Creating Your First Function ## πŸ“ Instructions: diff --git a/exercises/10-Creating-Your-First-Function/app.py b/exercises/09-Creating-Your-First-Function/app.py similarity index 100% rename from exercises/10-Creating-Your-First-Function/app.py rename to exercises/09-Creating-Your-First-Function/app.py diff --git a/exercises/10-Creating-Your-First-Function/test.py b/exercises/09-Creating-Your-First-Function/test.py similarity index 100% rename from exercises/10-Creating-Your-First-Function/test.py rename to exercises/09-Creating-Your-First-Function/test.py diff --git a/exercises/11-Create-A-New-Function/README.md b/exercises/10-Create-A-New-Function/README.md similarity index 97% rename from exercises/11-Create-A-New-Function/README.md rename to exercises/10-Create-A-New-Function/README.md index ccb0dd97..06c55d76 100644 --- a/exercises/11-Create-A-New-Function/README.md +++ b/exercises/10-Create-A-New-Function/README.md @@ -1,4 +1,4 @@ -# `11` Create a New Function +# `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: diff --git a/exercises/11-Create-A-New-Function/app.py b/exercises/10-Create-A-New-Function/app.py similarity index 100% rename from exercises/11-Create-A-New-Function/app.py rename to exercises/10-Create-A-New-Function/app.py diff --git a/exercises/11-Create-A-New-Function/test.py b/exercises/10-Create-A-New-Function/test.py similarity index 100% rename from exercises/11-Create-A-New-Function/test.py rename to exercises/10-Create-A-New-Function/test.py diff --git a/exercises/12-Your-First-If/README.md b/exercises/11-Your-First-If/README.md similarity index 95% rename from exercises/12-Your-First-If/README.md rename to exercises/11-Your-First-If/README.md index 24faba5a..f1e3109a 100644 --- a/exercises/12-Your-First-If/README.md +++ b/exercises/11-Your-First-If/README.md @@ -1,4 +1,4 @@ -# `12` Your First if... +# `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: diff --git a/exercises/12-Your-First-If/app.py b/exercises/11-Your-First-If/app.py similarity index 100% rename from exercises/12-Your-First-If/app.py rename to exercises/11-Your-First-If/app.py diff --git a/exercises/12-Your-First-If/test.py b/exercises/11-Your-First-If/test.py similarity index 100% rename from exercises/12-Your-First-If/test.py rename to exercises/11-Your-First-If/test.py diff --git a/exercises/13-How-Much-The-Wedding-Costs/README.md b/exercises/12-How-Much-The-Wedding-Costs/README.md similarity index 93% rename from exercises/13-How-Much-The-Wedding-Costs/README.md rename to exercises/12-How-Much-The-Wedding-Costs/README.md index fba41854..584ae8cb 100644 --- a/exercises/13-How-Much-The-Wedding-Costs/README.md +++ b/exercises/12-How-Much-The-Wedding-Costs/README.md @@ -1,4 +1,4 @@ -# `13` How Much The Wedding Costs (if...else) +# `12` How Much The Wedding Costs (if...else) Here is a table of prices for a wedding catering company: diff --git a/exercises/13-How-Much-The-Wedding-Costs/app.py b/exercises/12-How-Much-The-Wedding-Costs/app.py similarity index 100% rename from exercises/13-How-Much-The-Wedding-Costs/app.py rename to exercises/12-How-Much-The-Wedding-Costs/app.py diff --git a/exercises/13-How-Much-The-Wedding-Costs/test.py b/exercises/12-How-Much-The-Wedding-Costs/test.py similarity index 100% rename from exercises/13-How-Much-The-Wedding-Costs/test.py rename to exercises/12-How-Much-The-Wedding-Costs/test.py diff --git a/exercises/15-Random-Numbers/README.md b/exercises/13-Random-Numbers/README.md similarity index 95% rename from exercises/15-Random-Numbers/README.md rename to exercises/13-Random-Numbers/README.md index 83ea51bf..b2e808a8 100644 --- a/exercises/15-Random-Numbers/README.md +++ b/exercises/13-Random-Numbers/README.md @@ -1,4 +1,4 @@ -# `15` Random Numbers +# `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()**. diff --git a/exercises/15-Random-Numbers/app.py b/exercises/13-Random-Numbers/app.py similarity index 100% rename from exercises/15-Random-Numbers/app.py rename to exercises/13-Random-Numbers/app.py diff --git a/exercises/15-Random-Numbers/test.py b/exercises/13-Random-Numbers/test.py similarity index 100% rename from exercises/15-Random-Numbers/test.py rename to exercises/13-Random-Numbers/test.py diff --git a/exercises/16-Rand-From-One-to-Six/README.md b/exercises/14-Rand-From-One-to-Six/README.md similarity index 92% rename from exercises/16-Rand-From-One-to-Six/README.md rename to exercises/14-Rand-From-One-to-Six/README.md index d133fb5f..7e40dc6e 100644 --- a/exercises/16-Rand-From-One-to-Six/README.md +++ b/exercises/14-Rand-From-One-to-Six/README.md @@ -1,4 +1,4 @@ -# `16` Rand From 0 to 12 +# `14` Rand From 0 to 12 ## πŸ“ Instructions: diff --git a/exercises/16-Rand-From-One-to-Six/app.py b/exercises/14-Rand-From-One-to-Six/app.py similarity index 100% rename from exercises/16-Rand-From-One-to-Six/app.py rename to exercises/14-Rand-From-One-to-Six/app.py diff --git a/exercises/16-Rand-From-One-to-Six/test.py b/exercises/14-Rand-From-One-to-Six/test.py similarity index 100% rename from exercises/16-Rand-From-One-to-Six/test.py rename to exercises/14-Rand-From-One-to-Six/test.py diff --git a/exercises/14-Your-First-Switch/README.md b/exercises/14-Your-First-Switch/README.md deleted file mode 100644 index 558c6762..00000000 --- a/exercises/14-Your-First-Switch/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# `14` Your First Switch - -Python does not have a simple switch case construct. Coming from a Javascript or C++ background, you may find this to be a bit odd. -So, to get around this, we use Python’s built-in dictionary construct to implement cases and decided what to do when a case is met. -We can also specify what to do when none is met. - -One way out would be to implement an if-elif-else ladder. Rather, we can use a dictionary to map cases to their functionality. Here, -we define a function week() to tell us which day a certain day of the week is. A switcher is a dictionary that performs this mapping. - -```py -def week(i): - switcher={ - 0:'Sunday', - 1:'Monday', - 2:'Tuesday', - 3:'Wednesday', - 4:'Thursday', - 5:'Friday', - 6:'Saturday' - } - return switcher.get(i,"Invalid day of week") - -``` - -Now, we make calls to week() with different values. - -```py -week(2) - -``` -## πŸ“ Instructions: - -1. Complete this switch statement with 3 possible colors: Red, Green and Blue. - -The function needs to return **true** if the color is available or **false** if the color is not available. - diff --git a/exercises/14-Your-First-Switch/app.py b/exercises/14-Your-First-Switch/app.py deleted file mode 100644 index 73b2fc8c..00000000 --- a/exercises/14-Your-First-Switch/app.py +++ /dev/null @@ -1,20 +0,0 @@ -def get_color(color_name): - - switcher = { - 0:'Red', - 1:'red', - 2:'blue', - 3:'Blue', - 4:'green', - 5:'Green' - } - return switcher.get(color_name,"Invalid day of week") - - -color_input= str(input('What color do you want?\n')) -#print("$$$",get_color(color_input) -is_available = get_color(color_input) -if(is_available): - print('Good news! That color is available') -else: - print('We are sorry, that color is not available') \ No newline at end of file diff --git a/exercises/14-Your-First-Switch/test.py b/exercises/14-Your-First-Switch/test.py deleted file mode 100644 index 0d6ad4d0..00000000 --- a/exercises/14-Your-First-Switch/test.py +++ /dev/null @@ -1,21 +0,0 @@ -import io -import sys -sys.stdout = buffer = io.StringIO() - -# from app import my_function -import pytest - -@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('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/17-Your-First-Loop/README.md b/exercises/15-Your-First-Loop/README.md similarity index 93% rename from exercises/17-Your-First-Loop/README.md rename to exercises/15-Your-First-Loop/README.md index 818f301f..f25ce53b 100644 --- a/exercises/17-Your-First-Loop/README.md +++ b/exercises/15-Your-First-Loop/README.md @@ -1,4 +1,4 @@ -# `17` Your First Loop +# `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. diff --git a/exercises/17-Your-First-Loop/app.py b/exercises/15-Your-First-Loop/app.py similarity index 100% rename from exercises/17-Your-First-Loop/app.py rename to exercises/15-Your-First-Loop/app.py diff --git a/exercises/17-Your-First-Loop/test.py b/exercises/15-Your-First-Loop/test.py similarity index 100% rename from exercises/17-Your-First-Loop/test.py rename to exercises/15-Your-First-Loop/test.py diff --git a/exercises/18-Create-A-For-Loop/README.md b/exercises/16-Create-A-For-Loop/README.md similarity index 95% rename from exercises/18-Create-A-For-Loop/README.md rename to exercises/16-Create-A-For-Loop/README.md index 0bcee6b0..cd6985da 100644 --- a/exercises/18-Create-A-For-Loop/README.md +++ b/exercises/16-Create-A-For-Loop/README.md @@ -1,4 +1,4 @@ -# `18` Create A For Loop +# `16` Create A For Loop Loops are very useful, you don't have to repeat yourself by writing the same lines many times. diff --git a/exercises/18-Create-A-For-Loop/app.py b/exercises/16-Create-A-For-Loop/app.py similarity index 100% rename from exercises/18-Create-A-For-Loop/app.py rename to exercises/16-Create-A-For-Loop/app.py diff --git a/exercises/18-Create-A-For-Loop/test.py b/exercises/16-Create-A-For-Loop/test.py similarity index 100% rename from exercises/18-Create-A-For-Loop/test.py rename to exercises/16-Create-A-For-Loop/test.py diff --git a/exercises/19-While-Loop/README.md b/exercises/17-While-Loop/README.md similarity index 95% rename from exercises/19-While-Loop/README.md rename to exercises/17-While-Loop/README.md index 2cb7d33a..9410fb3d 100644 --- a/exercises/19-While-Loop/README.md +++ b/exercises/17-While-Loop/README.md @@ -1,4 +1,4 @@ -# `19` While Loop +# `17` While Loop This code is broken, it produces an infinite loop. Replit handles the infinite loop, for now. diff --git a/exercises/19-While-Loop/app.py b/exercises/17-While-Loop/app.py similarity index 100% rename from exercises/19-While-Loop/app.py rename to exercises/17-While-Loop/app.py diff --git a/exercises/19-While-Loop/test.py b/exercises/17-While-Loop/test.py similarity index 100% rename from exercises/19-While-Loop/test.py rename to exercises/17-While-Loop/test.py diff --git a/exercises/20-Random-Colors-Loop/README.md b/exercises/18-Random-Colors-Loop/README.md similarity index 96% rename from exercises/20-Random-Colors-Loop/README.md rename to exercises/18-Random-Colors-Loop/README.md index 6fca6bcb..efca924a 100644 --- a/exercises/20-Random-Colors-Loop/README.md +++ b/exercises/18-Random-Colors-Loop/README.md @@ -1,4 +1,4 @@ -# `20` Random Colors (Loop) +# `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). diff --git a/exercises/20-Random-Colors-Loop/app.py b/exercises/18-Random-Colors-Loop/app.py similarity index 100% rename from exercises/20-Random-Colors-Loop/app.py rename to exercises/18-Random-Colors-Loop/app.py diff --git a/exercises/20-Random-Colors-Loop/test.py b/exercises/18-Random-Colors-Loop/test.py similarity index 100% rename from exercises/20-Random-Colors-Loop/test.py rename to exercises/18-Random-Colors-Loop/test.py diff --git a/exercises/21-Looping-With-FizzBuzz/README.md b/exercises/19-Looping-With-FizzBuzz/README.md similarity index 95% rename from exercises/21-Looping-With-FizzBuzz/README.md rename to exercises/19-Looping-With-FizzBuzz/README.md index ad7fe2c6..9ed5f7a8 100644 --- a/exercises/21-Looping-With-FizzBuzz/README.md +++ b/exercises/19-Looping-With-FizzBuzz/README.md @@ -1,4 +1,4 @@ -# `21` Looping With FizzBuzz +# `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. diff --git a/exercises/21-Looping-With-FizzBuzz/app.py b/exercises/19-Looping-With-FizzBuzz/app.py similarity index 100% rename from exercises/21-Looping-With-FizzBuzz/app.py rename to exercises/19-Looping-With-FizzBuzz/app.py diff --git a/exercises/21-Looping-With-FizzBuzz/test.py b/exercises/19-Looping-With-FizzBuzz/test.py similarity index 100% rename from exercises/21-Looping-With-FizzBuzz/test.py rename to exercises/19-Looping-With-FizzBuzz/test.py diff --git a/exercises/22-Russian-Roulette/README.md b/exercises/20-Russian-Roulette/README.md similarity index 96% rename from exercises/22-Russian-Roulette/README.md rename to exercises/20-Russian-Roulette/README.md index fe145888..92e78bec 100644 --- a/exercises/22-Russian-Roulette/README.md +++ b/exercises/20-Russian-Roulette/README.md @@ -1,4 +1,4 @@ -# `22` Russian Roulette +# `20` Russian Roulette Have you ever played Russian Roulette? It's super fun! If you make it (wuuuajajajaja). diff --git a/exercises/22-Russian-Roulette/app.py b/exercises/20-Russian-Roulette/app.py similarity index 100% rename from exercises/22-Russian-Roulette/app.py rename to exercises/20-Russian-Roulette/app.py diff --git a/exercises/22-Russian-Roulette/test.py b/exercises/20-Russian-Roulette/test.py similarity index 100% rename from exercises/22-Russian-Roulette/test.py rename to exercises/20-Russian-Roulette/test.py diff --git a/exercises/23-The-Beatles/README.md b/exercises/21-The-Beatles/README.md similarity index 97% rename from exercises/23-The-Beatles/README.md rename to exercises/21-The-Beatles/README.md index f4c2c05b..7f8b1c63 100644 --- a/exercises/23-The-Beatles/README.md +++ b/exercises/21-The-Beatles/README.md @@ -1,4 +1,4 @@ -# `23` The Beatles +# `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.. :( diff --git a/exercises/23-The-Beatles/app.py b/exercises/21-The-Beatles/app.py similarity index 100% rename from exercises/23-The-Beatles/app.py rename to exercises/21-The-Beatles/app.py diff --git a/exercises/23-The-Beatles/test.py b/exercises/21-The-Beatles/test.py similarity index 100% rename from exercises/23-The-Beatles/test.py rename to exercises/21-The-Beatles/test.py diff --git a/exercises/24-Bottles-Of-Milk/README.md b/exercises/22-Bottles-Of-Milk/README.md similarity index 97% rename from exercises/24-Bottles-Of-Milk/README.md rename to exercises/22-Bottles-Of-Milk/README.md index 600d353f..ba2f2d08 100644 --- a/exercises/24-Bottles-Of-Milk/README.md +++ b/exercises/22-Bottles-Of-Milk/README.md @@ -1,4 +1,4 @@ -# `24` Bottles Of Milk +# `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 diff --git a/exercises/24-Bottles-Of-Milk/app.py b/exercises/22-Bottles-Of-Milk/app.py similarity index 100% rename from exercises/24-Bottles-Of-Milk/app.py rename to exercises/22-Bottles-Of-Milk/app.py diff --git a/exercises/24-Bottles-Of-Milk/test.py b/exercises/22-Bottles-Of-Milk/test.py similarity index 100% rename from exercises/24-Bottles-Of-Milk/test.py rename to exercises/22-Bottles-Of-Milk/test.py diff --git a/exercises/25-Python-Objects/README.md b/exercises/23-Python-Objects/README.md similarity index 67% rename from exercises/25-Python-Objects/README.md rename to exercises/23-Python-Objects/README.md index 8a860aff..273a2427 100644 --- a/exercises/25-Python-Objects/README.md +++ b/exercises/23-Python-Objects/README.md @@ -1,4 +1,4 @@ -# `25` Python Objects +# `23` Python Objects Often you'll find yourself wanting to save more information in less space, especially if it's all related. For example: @@ -36,42 +36,38 @@ 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: -```js - -var person = { - name: "John", //String - lastname: "Doe", - age: 35, //Number - gender: "male", - lucky_numbers: [ 7, 11, 13, 17], //Array - significant_other: person2 //Object, yes the same variable/object defined after -}; - -var person2 = { - name: "Jane", - lastname: "Doe", - age: 38, - gender: "female", - lucky_numbers: [ 2, 4, 6, 8], - significant_other: person -}; - -var family = { - lastname: "Doe", - members: [person, person2] //Array of objects -}; +```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); +print(family.members[0].name) ``` -Or the 3rd lucky number of the significant other of the second member of Doe's family: - -```Javascript -console.log( family.members[1].significant_other.lucky_numbers[2]); -``` Easy stuff :) ## πŸ“ Instructions: diff --git a/exercises/25-Python-Objects/app.py b/exercises/23-Python-Objects/app.py similarity index 100% rename from exercises/25-Python-Objects/app.py rename to exercises/23-Python-Objects/app.py diff --git a/exercises/25-Python-Objects/test.py b/exercises/23-Python-Objects/test.py similarity index 100% rename from exercises/25-Python-Objects/test.py rename to exercises/23-Python-Objects/test.py From 98144e75a9367e600ce4edf1ec91c33a66c0e680 Mon Sep 17 00:00:00 2001 From: Paolo Lucano Date: Mon, 7 Oct 2019 03:16:01 +0000 Subject: [PATCH 87/87] fixed issues 07-08-09-17-18 --- exercises/07-Create-a-Basic-HTML/README.md | 2 +- exercises/07-Create-a-Basic-HTML/app.py | 2 -- exercises/07-Create-a-Basic-HTML/test.py | 18 +++++++++--------- .../08-Calling-Your-First-Function/app.py | 3 +-- .../08-Calling-Your-First-Function/test.py | 9 --------- .../09-Creating-Your-First-Function/test.py | 2 +- exercises/17-While-Loop/README.md | 2 +- exercises/18-Random-Colors-Loop/app.py | 7 ++----- 8 files changed, 15 insertions(+), 30 deletions(-) diff --git a/exercises/07-Create-a-Basic-HTML/README.md b/exercises/07-Create-a-Basic-HTML/README.md index 2e978814..9601f021 100644 --- a/exercises/07-Create-a-Basic-HTML/README.md +++ b/exercises/07-Create-a-Basic-HTML/README.md @@ -12,7 +12,7 @@ the variables and concatenate them together to set the value of the variable **h 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. +2. Then, print the value of **html_document** on the console. The output should look like this: diff --git a/exercises/07-Create-a-Basic-HTML/app.py b/exercises/07-Create-a-Basic-HTML/app.py index 965df869..805349de 100644 --- a/exercises/07-Create-a-Basic-HTML/app.py +++ b/exercises/07-Create-a-Basic-HTML/app.py @@ -9,5 +9,3 @@ # DON'T CHANGE THE CODE ABOVE -html_document = e + c + g + a + f + h + d + b -print(html_document) \ No newline at end of file diff --git a/exercises/07-Create-a-Basic-HTML/test.py b/exercises/07-Create-a-Basic-HTML/test.py index eee3ee68..c8451a39 100644 --- a/exercises/07-Create-a-Basic-HTML/test.py +++ b/exercises/07-Create-a-Basic-HTML/test.py @@ -11,7 +11,16 @@ @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 == "\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(): @@ -24,12 +33,3 @@ def test_use_my_var1(): # 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]) -# @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/08-Calling-Your-First-Function/app.py b/exercises/08-Calling-Your-First-Function/app.py index c9841f59..371555bc 100644 --- a/exercises/08-Calling-Your-First-Function/app.py +++ b/exercises/08-Calling-Your-First-Function/app.py @@ -2,5 +2,4 @@ def is_odd(my_number): return (my_number % 2 != 0) -# your code here -print(is_odd(45345)) \ No newline at end of file +# your code here diff --git a/exercises/08-Calling-Your-First-Function/test.py b/exercises/08-Calling-Your-First-Function/test.py index 363aac97..09f6cc21 100644 --- a/exercises/08-Calling-Your-First-Function/test.py +++ b/exercises/08-Calling-Your-First-Function/test.py @@ -25,12 +25,3 @@ def test_conditional(): def test_for_file_output(capsys): captured = buffer.getvalue() assert captured == "True\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/09-Creating-Your-First-Function/test.py b/exercises/09-Creating-Your-First-Function/test.py index 32aca4e5..90013d15 100644 --- a/exercises/09-Creating-Your-First-Function/test.py +++ b/exercises/09-Creating-Your-First-Function/test.py @@ -15,7 +15,7 @@ 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 a+b" in s] + 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" diff --git a/exercises/17-While-Loop/README.md b/exercises/17-While-Loop/README.md index 9410fb3d..f5d6642a 100644 --- a/exercises/17-While-Loop/README.md +++ b/exercises/17-While-Loop/README.md @@ -6,7 +6,7 @@ Fix the problem, to print from 100 - 0. And return 0. ## πŸ’‘ Hint: -- To stop the infinite loop press **ctrl + c** and then run again **bc run:exercises -e=gitpod** +- 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/18-Random-Colors-Loop/app.py b/exercises/18-Random-Colors-Loop/app.py index 8220bf38..3902cf0f 100644 --- a/exercises/18-Random-Colors-Loop/app.py +++ b/exercises/18-Random-Colors-Loop/app.py @@ -16,14 +16,11 @@ def get_color(color_number=4): def get_allStudentColors(): - #your loop here example_color = 1 students_array = [] + #your loop here + - for i in range(11): - example_color = get_color(random.randint(0,4)) - students_array.append(example_color) - return students_array