From afb55bcfd910adb2e1e48bf0ba3aa52f6b4e348e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Su=C3=A1rez?= Date: Thu, 16 Dec 2021 02:20:09 +0000 Subject: [PATCH 01/10] excercise 11-Swap_digits fixed --- exercises/10-Two_digits/app.py | 2 +- exercises/11-Swap_digits/app.py | 1 + exercises/11-Swap_digits/test.py | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/10-Two_digits/app.py b/exercises/10-Two_digits/app.py index d6b6011e..bb47dde0 100644 --- a/exercises/10-Two_digits/app.py +++ b/exercises/10-Two_digits/app.py @@ -5,4 +5,4 @@ def two_digits(digit): #Invoke the function with any interger as its argument. -print(two_digits()) +print(two_digits(79)) diff --git a/exercises/11-Swap_digits/app.py b/exercises/11-Swap_digits/app.py index 697823fb..b0fe9347 100644 --- a/exercises/11-Swap_digits/app.py +++ b/exercises/11-Swap_digits/app.py @@ -7,3 +7,4 @@ def swap_digits(num): #Invoke the function with any two digit interger as its argument print(swap_digits()) + diff --git a/exercises/11-Swap_digits/test.py b/exercises/11-Swap_digits/test.py index a0054654..78cf2547 100644 --- a/exercises/11-Swap_digits/test.py +++ b/exercises/11-Swap_digits/test.py @@ -6,7 +6,8 @@ def test_for_functon_existence(capsys, app): @pytest.mark.it('The function swap_digits must swap the digits of a 2 digits integer') def test_for_file_output(capsys, app): - assert app.swap_digits(30) == str(30%10)+str(30//10) + assert app.swap_digits(30) == int(30%10)+int(30//10) + From 767297978eed0fd4d3e8146d54b9a44a06475745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Su=C3=A1rez?= Date: Sat, 15 Jan 2022 00:59:53 +0000 Subject: [PATCH 02/10] added some hints and tests --- .learn/resets/11-Swap_digits/app.py | 10 ++++++++++ exercises/11-Swap_digits/README.es.md | 10 +++++++++- exercises/11-Swap_digits/README.md | 10 +++++++++- exercises/11-Swap_digits/test.py | 25 ++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 .learn/resets/11-Swap_digits/app.py diff --git a/.learn/resets/11-Swap_digits/app.py b/.learn/resets/11-Swap_digits/app.py new file mode 100644 index 00000000..b0fe9347 --- /dev/null +++ b/.learn/resets/11-Swap_digits/app.py @@ -0,0 +1,10 @@ +#Complete the fuction to return the swapped digits of a given two-digit-interger. +def swap_digits(num): + return None + + + +#Invoke the function with any two digit interger as its argument +print(swap_digits()) + + diff --git a/exercises/11-Swap_digits/README.es.md b/exercises/11-Swap_digits/README.es.md index 3da4d630..2a53c93e 100644 --- a/exercises/11-Swap_digits/README.es.md +++ b/exercises/11-Swap_digits/README.es.md @@ -8,14 +8,22 @@ + 79 ++ 30 + ### Ejemplo de salida: + 97 ++ 3 + ## 馃挕 Pista: + Si no sabes c贸mo empezar la soluci贸n a esta asignaci贸n, por favor, revisa la teor铆a en esta lecci贸n: https://snakify.org/lessons/integer_float_numbers/ + Tambi茅n puedes intentar paso a paso con trozos de la teor铆a: -https://snakify.org/lessons/integer_float_numbers/steps/1/ \ No newline at end of file +https://snakify.org/lessons/integer_float_numbers/steps/1/ + ++ Ten en cuenta que para concatenar dos n煤meros puedes transformar su valor en un string con str(num). + ++ El valor a retornar debe ser un n煤mero entero. \ No newline at end of file diff --git a/exercises/11-Swap_digits/README.md b/exercises/11-Swap_digits/README.md index db5e824d..2a1353b1 100644 --- a/exercises/11-Swap_digits/README.md +++ b/exercises/11-Swap_digits/README.md @@ -8,14 +8,22 @@ + 79 ++ 30 + ###聽Example output: + 97 ++ 3 + ## 馃挕 Hint: + If you don't know how to start solving this assignment, please, review a theory for this lesson: https://snakify.org/lessons/integer_float_numbers/ + You may also try step-by-step theory chunks: -https://snakify.org/lessons/integer_float_numbers/steps/1/ \ No newline at end of file +https://snakify.org/lessons/integer_float_numbers/steps/1/ + ++ Note that you need to concatenate two numbers, so in order not to add those values you may have to convert them as a string (str) + ++ The function must return a number \ No newline at end of file diff --git a/exercises/11-Swap_digits/test.py b/exercises/11-Swap_digits/test.py index 78cf2547..89f1d79f 100644 --- a/exercises/11-Swap_digits/test.py +++ b/exercises/11-Swap_digits/test.py @@ -4,10 +4,33 @@ def test_for_functon_existence(capsys, app): assert callable(app.swap_digits) +# @pytest.mark.it('The function swap_digits must return something') +# def test_for_functon_return_statement(capsys, app): +# path = os.path.dirname(os.path.abspath(__file__))+'/app.py' +# with open(path, 'r') as content_file: +# content = content_file.read() +# regex = re.compile(r"return(\s*)([^a-zA-Z0-9_])\w+") +# assert bool(regex.search(content)) == True + + @pytest.mark.it('The function swap_digits must swap the digits of a 2 digits integer') def test_for_file_output(capsys, app): - assert app.swap_digits(30) == int(30%10)+int(30//10) + result = str(30%10)+str(30//10) + assert app.swap_digits(30) == int(result) + + +# @pytest.mark.it('The function swap_digits(30) shoud return 3 as an integer') +# def test_for_file_output(capsys, app): +# assert app.swap_digits(30) == 3 + +# @pytest.mark.it('The function swap_digits(30) shoud return 3 as an integer') +# def test_for_file_output(capsys, app): +# assert app.swap_digits(79) == 97 +# @pytest.mark.it('The function swap_digits(25) shoud return 52 as an integer') +# def test_for_file_output(capsys, app): +# assert app.swap_digits(35) == 53 + From b18d4ca85435fcacab5aa4bef1651ac73787e9f7 Mon Sep 17 00:00:00 2001 From: Tomas Gonzalez <56565994+tommygonzaleza@users.noreply.github.com> Date: Mon, 17 Jan 2022 16:57:26 -0400 Subject: [PATCH 03/10] Update README.es.md --- exercises/11-Swap_digits/README.es.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/exercises/11-Swap_digits/README.es.md b/exercises/11-Swap_digits/README.es.md index 2a53c93e..e20becb6 100644 --- a/exercises/11-Swap_digits/README.es.md +++ b/exercises/11-Swap_digits/README.es.md @@ -2,28 +2,26 @@ ## 馃摑 Instrucciones: -1. Dado un entero de dos d铆gitos, intercambia sus d铆gitos de posici贸n e imprime el resultado. +1. Crea una funci贸n llamada `swap_digits()` dado un n煤mero entero de dos d铆gitos, intercambia sus d铆gitos de posici贸n e imprime el resultado. -### Ejemplo de entrada: +## Ejemplo de entrada: -+ 79 +``` +swap_digits(79) +``` -+ 30 +## Ejemplo de salida: -### Ejemplo de salida: - -+ 97 - -+ 3 +``` +97 +``` ## 馃挕 Pista: -+ Si no sabes c贸mo empezar la soluci贸n a esta asignaci贸n, por favor, revisa la teor铆a en esta lecci贸n: -https://snakify.org/lessons/integer_float_numbers/ ++ Si no sabes c贸mo empezar la soluci贸n a esta asignaci贸n, por favor, revisa la teor铆a en esta lecci贸n: https://snakify.org/lessons/integer_float_numbers/ -+ Tambi茅n puedes intentar paso a paso con trozos de la teor铆a: -https://snakify.org/lessons/integer_float_numbers/steps/1/ ++ Tambi茅n puedes intentar paso a paso con parte de la teor铆a: https://snakify.org/lessons/integer_float_numbers/steps/1/ + Ten en cuenta que para concatenar dos n煤meros puedes transformar su valor en un string con str(num). -+ El valor a retornar debe ser un n煤mero entero. \ No newline at end of file ++ El valor a retornar debe ser un n煤mero entero. From c9ebf06af6f26ed2e8c2e84bc25ba976042eca2b Mon Sep 17 00:00:00 2001 From: Tomas Gonzalez <56565994+tommygonzaleza@users.noreply.github.com> Date: Mon, 17 Jan 2022 17:00:53 -0400 Subject: [PATCH 04/10] Update README.md --- exercises/11-Swap_digits/README.md | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/exercises/11-Swap_digits/README.md b/exercises/11-Swap_digits/README.md index 2a1353b1..e32ebe2d 100644 --- a/exercises/11-Swap_digits/README.md +++ b/exercises/11-Swap_digits/README.md @@ -2,28 +2,26 @@ ## 馃摑 Instructions: -1. Given a two-digit integer, swap its digits and print the result. +1. Create a function named `swap_digits()` given a two-digit integer, swap its digits and print the result. -###聽Example input: +##聽Example input: -+ 79 +```py +swap_digits(79) +``` -+ 30 +##聽Example output: -###聽Example output: - -+ 97 - -+ 3 +``` +97 +``` ## 馃挕 Hint: -+ If you don't know how to start solving this assignment, please, review a theory for this lesson: -https://snakify.org/lessons/integer_float_numbers/ ++ If you don't know how to start solving this assignment, please, review a theory for this lesson: https://snakify.org/lessons/integer_float_numbers/ -+ You may also try step-by-step theory chunks: -https://snakify.org/lessons/integer_float_numbers/steps/1/ ++ You can also try step-by-step with theory chunks: https://snakify.org/lessons/integer_float_numbers/steps/1/ -+ Note that you need to concatenate two numbers, so in order not to add those values you may have to convert them as a string (str) ++ Note that you need to concatenate two numbers, so you may have to convert them into a string `str(number)`. -+ The function must return a number \ No newline at end of file ++ The function must return a number. From e72819ae41a91718f89bb18494b94a1d6700481b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Su=C3=A1rez?= Date: Fri, 21 Jan 2022 17:27:48 +0000 Subject: [PATCH 05/10] done --- .learn/resets/11-Swap_digits/app.py | 10 --------- exercises/11-Swap_digits/app.py | 5 +++-- exercises/11-Swap_digits/test.py | 35 +++++++++++------------------ 3 files changed, 16 insertions(+), 34 deletions(-) delete mode 100644 .learn/resets/11-Swap_digits/app.py diff --git a/.learn/resets/11-Swap_digits/app.py b/.learn/resets/11-Swap_digits/app.py deleted file mode 100644 index b0fe9347..00000000 --- a/.learn/resets/11-Swap_digits/app.py +++ /dev/null @@ -1,10 +0,0 @@ -#Complete the fuction to return the swapped digits of a given two-digit-interger. -def swap_digits(num): - return None - - - -#Invoke the function with any two digit interger as its argument -print(swap_digits()) - - diff --git a/exercises/11-Swap_digits/app.py b/exercises/11-Swap_digits/app.py index b0fe9347..85b44ac1 100644 --- a/exercises/11-Swap_digits/app.py +++ b/exercises/11-Swap_digits/app.py @@ -1,10 +1,11 @@ #Complete the fuction to return the swapped digits of a given two-digit-interger. def swap_digits(num): - return None + result = str(num%10)+str(num//10) + return int(result) #Invoke the function with any two digit interger as its argument -print(swap_digits()) +print(swap_digits(76)) diff --git a/exercises/11-Swap_digits/test.py b/exercises/11-Swap_digits/test.py index 89f1d79f..1ac34a2e 100644 --- a/exercises/11-Swap_digits/test.py +++ b/exercises/11-Swap_digits/test.py @@ -4,33 +4,24 @@ def test_for_functon_existence(capsys, app): assert callable(app.swap_digits) -# @pytest.mark.it('The function swap_digits must return something') -# def test_for_functon_return_statement(capsys, app): -# path = os.path.dirname(os.path.abspath(__file__))+'/app.py' -# with open(path, 'r') as content_file: -# content = content_file.read() -# regex = re.compile(r"return(\s*)([^a-zA-Z0-9_])\w+") -# assert bool(regex.search(content)) == True +@pytest.mark.it('The function swap_digits must return something') +def test_for_functon_return_statement(capsys, app): + path = os.path.dirname(os.path.abspath(__file__))+'/app.py' + with open(path, 'r') as content_file: + content = content_file.read() + regex = re.compile(r"return(\s*)[^a-zA-Z0-9_]\w+") + assert bool(regex.search(content)) == True - -@pytest.mark.it('The function swap_digits must swap the digits of a 2 digits integer') -def test_for_file_output(capsys, app): - result = str(30%10)+str(30//10) - assert app.swap_digits(30) == int(result) +@pytest.mark.it('If `swap_digits` recieve 30 should return 3 as an integer') +def test_for_file_output(capsys, app): + assert app.swap_digits(30) == 3 -# @pytest.mark.it('The function swap_digits(30) shoud return 3 as an integer') -# def test_for_file_output(capsys, app): -# assert app.swap_digits(30) == 3 - +@pytest.mark.it('The function `swap_digits` must swap the digits of a 2 digits integer') +def test_for_file_output(capsys, app): + assert app.swap_digits(79) == 97 -# @pytest.mark.it('The function swap_digits(30) shoud return 3 as an integer') -# def test_for_file_output(capsys, app): -# assert app.swap_digits(79) == 97 -# @pytest.mark.it('The function swap_digits(25) shoud return 52 as an integer') -# def test_for_file_output(capsys, app): -# assert app.swap_digits(35) == 53 From f7f4db33efe1d3352645b7e48a492b9d3604837e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Su=C3=A1rez?= Date: Fri, 21 Jan 2022 17:31:27 +0000 Subject: [PATCH 06/10] done --- exercises/11-Swap_digits/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/11-Swap_digits/app.py b/exercises/11-Swap_digits/app.py index 85b44ac1..a1fbdc8b 100644 --- a/exercises/11-Swap_digits/app.py +++ b/exercises/11-Swap_digits/app.py @@ -1,7 +1,7 @@ #Complete the fuction to return the swapped digits of a given two-digit-interger. def swap_digits(num): result = str(num%10)+str(num//10) - return int(result) + return (result) From 1b96993cd63d66fa5790ac6c8131296f75afb00e Mon Sep 17 00:00:00 2001 From: Tomas Gonzalez <56565994+tommygonzaleza@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:32:07 -0400 Subject: [PATCH 07/10] Update app.py --- exercises/11-Swap_digits/app.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/exercises/11-Swap_digits/app.py b/exercises/11-Swap_digits/app.py index a1fbdc8b..b7e93a2f 100644 --- a/exercises/11-Swap_digits/app.py +++ b/exercises/11-Swap_digits/app.py @@ -1,11 +1,8 @@ #Complete the fuction to return the swapped digits of a given two-digit-interger. def swap_digits(num): - result = str(num%10)+str(num//10) - return (result) + # Your code here #Invoke the function with any two digit interger as its argument print(swap_digits(76)) - - From 75e747f727360d3a527e0c2a3d150c9dd7aa8b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Su=C3=A1rez?= Date: Tue, 25 Jan 2022 21:34:43 +0000 Subject: [PATCH 08/10] 11-Swap_digits --- exercises/11-Swap_digits/test.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/exercises/11-Swap_digits/test.py b/exercises/11-Swap_digits/test.py index 1ac34a2e..5d94f4a4 100644 --- a/exercises/11-Swap_digits/test.py +++ b/exercises/11-Swap_digits/test.py @@ -1,27 +1,25 @@ -import io, sys, pytest, os, re, mock +import io, sys, pytest, os, re, mock, app + +# @pytest.mark.it('The function swap_digits must exist') +# def test_for_functon_existence(): +# assert callable(app.swap_digits) @pytest.mark.it('The function swap_digits must exist') -def test_for_functon_existence(capsys, app): - assert callable(app.swap_digits) +def test_function_exists(): + assert app.swap_digits @pytest.mark.it('The function swap_digits must return something') -def test_for_functon_return_statement(capsys, app): - path = os.path.dirname(os.path.abspath(__file__))+'/app.py' - with open(path, 'r') as content_file: - content = content_file.read() - regex = re.compile(r"return(\s*)[^a-zA-Z0-9_]\w+") - assert bool(regex.search(content)) == True +def test_return_exists(): + assert app.swap_digits(12) != None +@pytest.mark.it('The function swap_digits should return an integer') +def test_return_integer(): + assert type(app.swap_digits(23)) == type(1) -@pytest.mark.it('If `swap_digits` recieve 30 should return 3 as an integer') +@pytest.mark.it('If `swap_digits` recieve 30 should return 3') def test_for_file_output(capsys, app): assert app.swap_digits(30) == 3 -@pytest.mark.it('The function `swap_digits` must swap the digits of a 2 digits integer') +@pytest.mark.it('The function `swap_digits` must swap the digits') def test_for_file_output(capsys, app): - assert app.swap_digits(79) == 97 - - - - - + assert app.swap_digits(79) == 97 or app.swap_digits(79) == "97" \ No newline at end of file From e84dd26b0baec59f5d99c364e1f8f5246736fcfc Mon Sep 17 00:00:00 2001 From: Tomas Gonzalez Date: Wed, 26 Jan 2022 20:18:08 +0000 Subject: [PATCH 09/10] Tests improved --- exercises/11-Swap_digits/README.md | 4 ++-- exercises/11-Swap_digits/app.py | 12 +++++++++--- exercises/11-Swap_digits/test.py | 14 +++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/exercises/11-Swap_digits/README.md b/exercises/11-Swap_digits/README.md index e32ebe2d..e63c9a90 100644 --- a/exercises/11-Swap_digits/README.md +++ b/exercises/11-Swap_digits/README.md @@ -4,13 +4,13 @@ 1. Create a function named `swap_digits()` given a two-digit integer, swap its digits and print the result. -##聽Example input: +## Example input: ```py swap_digits(79) ``` -##聽Example output: +## Example output: ``` 97 diff --git a/exercises/11-Swap_digits/app.py b/exercises/11-Swap_digits/app.py index b7e93a2f..f4f4e46f 100644 --- a/exercises/11-Swap_digits/app.py +++ b/exercises/11-Swap_digits/app.py @@ -1,8 +1,14 @@ #Complete the fuction to return the swapped digits of a given two-digit-interger. def swap_digits(num): # Your code here - - + num = str(num) + s = "" + first_value = num[0] + second_value = num[1] + s+=second_value + s+=first_value + return s + #Invoke the function with any two digit interger as its argument -print(swap_digits(76)) +print(swap_digits(30)) \ No newline at end of file diff --git a/exercises/11-Swap_digits/test.py b/exercises/11-Swap_digits/test.py index 5d94f4a4..9c9f61ab 100644 --- a/exercises/11-Swap_digits/test.py +++ b/exercises/11-Swap_digits/test.py @@ -1,9 +1,5 @@ import io, sys, pytest, os, re, mock, app -# @pytest.mark.it('The function swap_digits must exist') -# def test_for_functon_existence(): -# assert callable(app.swap_digits) - @pytest.mark.it('The function swap_digits must exist') def test_function_exists(): assert app.swap_digits @@ -16,10 +12,10 @@ def test_return_exists(): def test_return_integer(): assert type(app.swap_digits(23)) == type(1) -@pytest.mark.it('If `swap_digits` recieve 30 should return 3') +@pytest.mark.it('The function `swap_digits` must swap the digits. Testing with 79') def test_for_file_output(capsys, app): - assert app.swap_digits(30) == 3 + assert app.swap_digits(79) == 97 -@pytest.mark.it('The function `swap_digits` must swap the digits') -def test_for_file_output(capsys, app): - assert app.swap_digits(79) == 97 or app.swap_digits(79) == "97" \ No newline at end of file +@pytest.mark.it('The function `swap_digits` must swap the digits. Testing with 30') +def test_for_file_output_2(capsys, app): + assert app.swap_digits(30) == 3 From a40cfb9be14275c4b420fd3df4e47262c3e8ba88 Mon Sep 17 00:00:00 2001 From: Tomas Gonzalez <56565994+tommygonzaleza@users.noreply.github.com> Date: Wed, 26 Jan 2022 16:19:18 -0400 Subject: [PATCH 10/10] Update app.py --- exercises/11-Swap_digits/app.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/exercises/11-Swap_digits/app.py b/exercises/11-Swap_digits/app.py index f4f4e46f..d60c443c 100644 --- a/exercises/11-Swap_digits/app.py +++ b/exercises/11-Swap_digits/app.py @@ -1,14 +1,7 @@ #Complete the fuction to return the swapped digits of a given two-digit-interger. def swap_digits(num): # Your code here - num = str(num) - s = "" - first_value = num[0] - second_value = num[1] - s+=second_value - s+=first_value - return s #Invoke the function with any two digit interger as its argument -print(swap_digits(30)) \ No newline at end of file +print(swap_digits(30))