From ec5641ce2f6b47189c420c111a87165b900305a9 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:24:58 +0100 Subject: [PATCH 01/83] Update solution.hide.py --- exercises/35-square-each-odd-number/solution.hide.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/exercises/35-square-each-odd-number/solution.hide.py b/exercises/35-square-each-odd-number/solution.hide.py index e76b71d3..15da0957 100644 --- a/exercises/35-square-each-odd-number/solution.hide.py +++ b/exercises/35-square-each-odd-number/solution.hide.py @@ -1,3 +1,8 @@ -values = raw_input() -numbers = [x for x in values.split(",") if int(x)%2!=0] -print ",".join(numbers) \ No newline at end of file +# Your code here +def square_odd_numbers(numbers): + number_list = [int(num) for num in numbers.split(',')] + squared_odd_numbers = [num**2 for num in number_list if num % 2 != 0] + + return squared_odd_numbers + +print(square_odd_numbers("1,2,3,4,5,6,7")) From f7534ae93729394ba04221a92173c67283ae4452 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:26:07 +0100 Subject: [PATCH 02/83] Update app.py --- exercises/35-square-each-odd-number/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/35-square-each-odd-number/app.py b/exercises/35-square-each-odd-number/app.py index e69de29b..a51f0856 100644 --- a/exercises/35-square-each-odd-number/app.py +++ b/exercises/35-square-each-odd-number/app.py @@ -0,0 +1 @@ +# Your code here From ad171110887b854de8e81324b98a6b2b72bb7f36 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:42:58 +0100 Subject: [PATCH 03/83] Update README.md --- exercises/35-square-each-odd-number/README.md | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/exercises/35-square-each-odd-number/README.md b/exercises/35-square-each-odd-number/README.md index a8d8113f..af05ae6d 100644 --- a/exercises/35-square-each-odd-number/README.md +++ b/exercises/35-square-each-odd-number/README.md @@ -1,8 +1,17 @@ -Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers. -Suppose the following input is supplied to the program: -1,2,3,4,5,6,7,8,9 -Then, the output should be: -1,3,5,7,9 - -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. \ No newline at end of file +# `35` Square odd numbers + +## 📝 Instructions: + +1. Write a function named `square_odd_numbers()` that accepts a string of comma-separated numbers as input, squares only the odd numbers, and returns the results as a list. + +## 📎 Example input: + +```py +square_odd_numbers("1,2,3,4,5,6,7,8,9") +``` + +## 📎 Example output: + +```py +[1, 9, 25, 49, 81] +``` From 58cb51ca6e3579b75468e630aca1e3c11614af34 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:47:30 +0100 Subject: [PATCH 04/83] Create README.es.md --- .../35-square-each-odd-number/README.es.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 exercises/35-square-each-odd-number/README.es.md diff --git a/exercises/35-square-each-odd-number/README.es.md b/exercises/35-square-each-odd-number/README.es.md new file mode 100644 index 00000000..629cf9ab --- /dev/null +++ b/exercises/35-square-each-odd-number/README.es.md @@ -0,0 +1,17 @@ +# `35` Square odd numbers + +## 📝 Instrucciones: + +1. Escribe una función llamada `square_odd_numbers()` que acepte un string de números separados por comas como entrada, eleve al cuadrado solo los números impares y devuelva los resultados en una lista. + +## 📎 Ejemplo de entrada: + +```py +square_odd_numbers("1,2,3,4,5,6,7,8,9") +``` + +## 📎 Ejemplo de salida: + +```py +[1, 9, 25, 49, 81] +``` From ec7c4043bedb71391e0654d7a971cdcc6d3c5b65 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:59:34 +0100 Subject: [PATCH 05/83] Update solution.hide.py --- exercises/36-net-amount/solution.hide.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/exercises/36-net-amount/solution.hide.py b/exercises/36-net-amount/solution.hide.py index a6a55ceb..72d6355b 100644 --- a/exercises/36-net-amount/solution.hide.py +++ b/exercises/36-net-amount/solution.hide.py @@ -1,9 +1,12 @@ +# Your code here def net_amount(param): - netAmount = 0 + total = 0 values = param.split() for x in range(len(values)): if values[x] == 'D': - netAmount+=int(values[x+1]) + total+=int(values[x+1]) elif values[x] == 'W': - netAmount-=int(values[x+1]) - return netAmount + total-=int(values[x+1]) + return total + +print(net_amount("D 300 W 200 D 400")) From bbb37345a40fe35722819191a790158e73367c09 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:59:44 +0100 Subject: [PATCH 06/83] Update app.py --- exercises/36-net-amount/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/36-net-amount/app.py b/exercises/36-net-amount/app.py index e69de29b..a51f0856 100644 --- a/exercises/36-net-amount/app.py +++ b/exercises/36-net-amount/app.py @@ -0,0 +1 @@ +# Your code here From 9a632978a1d18f008b4658b79b896b9c778dedd3 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:01:04 +0100 Subject: [PATCH 07/83] Update test.py --- exercises/36-net-amount/test.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/exercises/36-net-amount/test.py b/exercises/36-net-amount/test.py index ce3e5b3f..a28cce3c 100644 --- a/exercises/36-net-amount/test.py +++ b/exercises/36-net-amount/test.py @@ -1,10 +1,6 @@ import pytest, io, sys, json, mock, re, os path = os.path.dirname(os.path.abspath(__file__))+'/app.py' -@pytest.mark.it('The function net_amount must exist') -def test_function_existence(capsys, app): - assert app.net_amount - @pytest.mark.it('The function net_amount must exist') def test_function_existence(capsys, app): assert app.net_amount @@ -19,4 +15,4 @@ def test_output_2(capsys, app): @pytest.mark.it('The solution should work with other parameters. Testing with "W 300 D 300 W 200 D 300"') def test_output_negative(capsys, app): - assert app.net_amount("W 300 D 300 W 200 W 300") == -500 \ No newline at end of file + assert app.net_amount("W 300 D 300 W 200 W 300") == -500 From d3d8066f0c7732b9a20660e85fdbd104206bde29 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:03:58 +0100 Subject: [PATCH 08/83] Update README.md --- exercises/36-net-amount/README.md | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/exercises/36-net-amount/README.md b/exercises/36-net-amount/README.md index 9638a5c4..6709f86e 100644 --- a/exercises/36-net-amount/README.md +++ b/exercises/36-net-amount/README.md @@ -1,15 +1,22 @@ -Write a program that computes the net amount of a bank account based a transaction log from console input. The transaction log format is shown as following: -D 100 -W 200 - -D means deposit while W means withdrawal. -Suppose the following input is supplied to the program: -D 300 -D 300 -W 200 -D 100 -Then, the output should be: -500 +# `36` Net amount + +## 📝 Instructions: + +1. Write a function named `net_amount()` that computes the net amount of a bank account based on a transaction log from console input. The transaction log format is shown as following: + ++ D 100 ++ W 200 + +`D` means deposit while `W` means withdrawal. -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. \ No newline at end of file +## 📎 Example input: + +```py +net_amount("D 300 D 300 W 200 D 100") +``` + +## 📎 Example output: + +```py +500 +``` From aa9dc789a2780e3bdb0912c206e4c772251851da Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:30:12 +0100 Subject: [PATCH 09/83] Create README.es.md --- exercises/36-net-amount/README.es.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 exercises/36-net-amount/README.es.md diff --git a/exercises/36-net-amount/README.es.md b/exercises/36-net-amount/README.es.md new file mode 100644 index 00000000..6b93e91c --- /dev/null +++ b/exercises/36-net-amount/README.es.md @@ -0,0 +1,22 @@ +# `36` Net amount + +## 📝 Instrucciones: + +1. Escribe una función llamada `net_amount()` que calcule el saldo neto de una cuenta bancaria basándose en un registro de transacciones ingresado desde la entrada. El formato del registro de transacciones se muestra a continuación: + ++ D 100 ++ W 200 + +`D` significa depósito y `W` significa retiro. + +## 📎 Ejemplo de entrada: + +```py +net_amount("D 300 D 300 W 200 D 100") +``` + +## 📎 Ejemplo de salida: + +```py +500 +``` From e826bd8d136b0371f5e3cb5d03390d560587bd6d Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:32:01 +0100 Subject: [PATCH 10/83] Update README.es.md --- exercises/36-net-amount/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/36-net-amount/README.es.md b/exercises/36-net-amount/README.es.md index 6b93e91c..74e63346 100644 --- a/exercises/36-net-amount/README.es.md +++ b/exercises/36-net-amount/README.es.md @@ -2,7 +2,7 @@ ## 📝 Instrucciones: -1. Escribe una función llamada `net_amount()` que calcule el saldo neto de una cuenta bancaria basándose en un registro de transacciones ingresado desde la entrada. El formato del registro de transacciones se muestra a continuación: +1. Escribe una función llamada `net_amount()` que calcule el saldo neto de una cuenta bancaria basándose en un registro de transacciones ingresado por parámetro. El formato del registro de transacciones se muestra a continuación: + D 100 + W 200 From d0500b65b2331ed3247613b182903d4dddf5c5ef Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:32:41 +0100 Subject: [PATCH 11/83] Update README.md --- exercises/36-net-amount/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/36-net-amount/README.md b/exercises/36-net-amount/README.md index 6709f86e..989f6b21 100644 --- a/exercises/36-net-amount/README.md +++ b/exercises/36-net-amount/README.md @@ -2,7 +2,7 @@ ## 📝 Instructions: -1. Write a function named `net_amount()` that computes the net amount of a bank account based on a transaction log from console input. The transaction log format is shown as following: +1. Write a function named `net_amount()` that computes the net amount of a bank account based on a transaction log from input. The transaction log format is shown as following: + D 100 + W 200 From 72c478029d29ee644b5ba5da42fe07d4d5b49fac Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:49:57 +0100 Subject: [PATCH 12/83] Update README.md --- exercises/37-validity-of-password/README.md | 38 ++++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/exercises/37-validity-of-password/README.md b/exercises/37-validity-of-password/README.md index d8129ea3..7db3c5d0 100644 --- a/exercises/37-validity-of-password/README.md +++ b/exercises/37-validity-of-password/README.md @@ -1,28 +1,32 @@ -A website requires the users to input username and password to register. Write a program to check the validity of password input by users. -Following are the criteria for checking the password: +# `37` Validity of password + +## 📝 Instructions: + +A website requires the users to input username and password to register. Write a function named `valid_password()` to check the validity of password input by users. Following are the criteria for checking the password: 1. At least 1 letter between [a-z]. 2. At least 1 number between [0-9]. -1. At least 1 letter between [A-Z]. -3. At least 1 character from [$#@]. -4. Minimum length of transaction password: 6. -5. Maximum length of transaction password: 12. - +3. At least 1 letter between [A-Z]. +4. At least 1 character from [$#@]. +5. Minimum length of password: 6. +6. Maximum length of password: 12. Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. -### Example +## 📎 Example input: -If the following passwords are given as input to the program: - -``` -ABd1234@1,a F1#,2w3E*,2We3345 -``` -Then, the output of the program should be: +```text +valid_password(ABd1234@1,a F1#,2w3E*,2We3345) ``` + +## 📎 Example output: + +```text ABd1234@1 ``` - -### Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. +## 💡 Hints: + ++ Read about regular expressions in Python. + ++ You will need the `search()` function. From 252579f8258016178cb04ca2857e848852b1321a Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:51:18 +0100 Subject: [PATCH 13/83] Update README.md --- exercises/37-validity-of-password/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/37-validity-of-password/README.md b/exercises/37-validity-of-password/README.md index 7db3c5d0..b4e3dd53 100644 --- a/exercises/37-validity-of-password/README.md +++ b/exercises/37-validity-of-password/README.md @@ -2,7 +2,7 @@ ## 📝 Instructions: -A website requires the users to input username and password to register. Write a function named `valid_password()` to check the validity of password input by users. Following are the criteria for checking the password: +A website requires the users to input a username and password to register. Write a function named `valid_password()` to check the validity of password input by users. Following are the criteria for checking the password: 1. At least 1 letter between [a-z]. 2. At least 1 number between [0-9]. @@ -11,7 +11,7 @@ A website requires the users to input username and password to register. Write a 5. Minimum length of password: 6. 6. Maximum length of password: 12. -Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. +Your program should accept a sequence of comma separated passwords and check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. ## 📎 Example input: From 285882d2724df8fe21a6199e6d06fa851cfee49a Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:51:34 +0100 Subject: [PATCH 14/83] Update app.py --- exercises/37-validity-of-password/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/37-validity-of-password/app.py b/exercises/37-validity-of-password/app.py index e69de29b..a51f0856 100644 --- a/exercises/37-validity-of-password/app.py +++ b/exercises/37-validity-of-password/app.py @@ -0,0 +1 @@ +# Your code here From bd8222110865ab2c6f8120e60af04aaf41f9f4b2 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:51:39 +0100 Subject: [PATCH 15/83] Update app.py From 95337e995a4488d8df6ee9d3b6a693306e408409 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:12:38 +0100 Subject: [PATCH 16/83] Create README.es.md --- .../37-validity-of-password/README.es.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 exercises/37-validity-of-password/README.es.md diff --git a/exercises/37-validity-of-password/README.es.md b/exercises/37-validity-of-password/README.es.md new file mode 100644 index 00000000..caa4cae7 --- /dev/null +++ b/exercises/37-validity-of-password/README.es.md @@ -0,0 +1,34 @@ +# `37` Validity of password + +## 📝 Instrucciones: + +Un sitio web requiere que los usuarios ingresen un nombre de usuario y una contraseña para registrarse. Escribe una función llamada `valid_password()` para verificar la validez de la contraseña ingresada por los usuarios. A continuación, se detallan los criterios para verificar la contraseña: + +1. Al menos 1 letra entre [a-z]. +2. Al menos 1 número entre [0-9]. +3. Al menos 1 letra entre [A-Z]. +4. Al menos 1 carácter de [$#@]. +5. Longitud mínima de la contraseña: 6. +6. Longitud máxima de la contraseña: 12. + +Tu programa debería aceptar una secuencia de contraseñas separadas por comas y verificarlas según los criterios anteriores. Las contraseñas que cumplan con los criterios deben imprimirse, cada una separada por una coma. + +## 📎 Ejemplo de entrada: + +```text +valid_password(ABd1234@1,a F1#,2w3E*,2We3345) +``` + +## 📎 Ejemplo de salida: + +```text +ABd1234@1 +``` + +## 💡 Pistas: + ++ Lee sobre expresiones regulares en Python. + ++ Necesitarás importar el módulo 're' (regular expressions) para poder usar la función `search()`. + ++ Para importarlo, copia y pega lo siguiente al inicio de tu archivo `import re`. From ee3f111de204ed3a0f6f9127641788a0beb382b0 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:14:44 +0100 Subject: [PATCH 17/83] Update README.md --- exercises/37-validity-of-password/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/37-validity-of-password/README.md b/exercises/37-validity-of-password/README.md index b4e3dd53..b46737f3 100644 --- a/exercises/37-validity-of-password/README.md +++ b/exercises/37-validity-of-password/README.md @@ -16,7 +16,7 @@ Your program should accept a sequence of comma separated passwords and check the ## 📎 Example input: ```text -valid_password(ABd1234@1,a F1#,2w3E*,2We3345) +valid_password("ABd1234@1,a F1#,2w3E*,2We3345") ``` ## 📎 Example output: From 9fb27731eadc510402d8dbb522da2a75b84ad586 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:14:56 +0100 Subject: [PATCH 18/83] Update README.es.md --- exercises/37-validity-of-password/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/37-validity-of-password/README.es.md b/exercises/37-validity-of-password/README.es.md index caa4cae7..1977aca5 100644 --- a/exercises/37-validity-of-password/README.es.md +++ b/exercises/37-validity-of-password/README.es.md @@ -16,7 +16,7 @@ Tu programa debería aceptar una secuencia de contraseñas separadas por comas y ## 📎 Ejemplo de entrada: ```text -valid_password(ABd1234@1,a F1#,2w3E*,2We3345) +valid_password("ABd1234@1,a F1#,2w3E*,2We3345") ``` ## 📎 Ejemplo de salida: From dc8d00f3fa5137d5658cb8d6fc2eda54eda0f93c Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:16:32 +0100 Subject: [PATCH 19/83] Update README.md --- exercises/37-validity-of-password/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/37-validity-of-password/README.md b/exercises/37-validity-of-password/README.md index b46737f3..5a1b8cb7 100644 --- a/exercises/37-validity-of-password/README.md +++ b/exercises/37-validity-of-password/README.md @@ -11,7 +11,7 @@ A website requires the users to input a username and password to register. Write 5. Minimum length of password: 6. 6. Maximum length of password: 12. -Your program should accept a sequence of comma separated passwords and check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. +Your program should accept a sequence of comma-separated passwords and check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. ## 📎 Example input: @@ -29,4 +29,6 @@ ABd1234@1 + Read about regular expressions in Python. -+ You will need the `search()` function. ++ You will need to import the 're' module (regular expressions) to be able to use the `search()` function. + ++ To import it, copy and paste the following at the beginning of your file: `import re`. From 0b919977b96c8263276a087e91e5c39941faf5d8 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:16:57 +0100 Subject: [PATCH 20/83] Update README.md --- exercises/37-validity-of-password/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/37-validity-of-password/README.md b/exercises/37-validity-of-password/README.md index 5a1b8cb7..d87f51f2 100644 --- a/exercises/37-validity-of-password/README.md +++ b/exercises/37-validity-of-password/README.md @@ -15,7 +15,7 @@ Your program should accept a sequence of comma-separated passwords and check the ## 📎 Example input: -```text +```py valid_password("ABd1234@1,a F1#,2w3E*,2We3345") ``` From 236281d00ec42f8cbd0d225dbf0ff4da4c5364a1 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:17:06 +0100 Subject: [PATCH 21/83] Update README.es.md --- exercises/37-validity-of-password/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/37-validity-of-password/README.es.md b/exercises/37-validity-of-password/README.es.md index 1977aca5..b6459b4e 100644 --- a/exercises/37-validity-of-password/README.es.md +++ b/exercises/37-validity-of-password/README.es.md @@ -15,7 +15,7 @@ Tu programa debería aceptar una secuencia de contraseñas separadas por comas y ## 📎 Ejemplo de entrada: -```text +```py valid_password("ABd1234@1,a F1#,2w3E*,2We3345") ``` From 459bc2fcd226dc8871f8becd2bbe5bba963f2329 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:18:39 +0100 Subject: [PATCH 22/83] Update solution.hide.py --- exercises/37-validity-of-password/solution.hide.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exercises/37-validity-of-password/solution.hide.py b/exercises/37-validity-of-password/solution.hide.py index eef5c148..17ba8386 100644 --- a/exercises/37-validity-of-password/solution.hide.py +++ b/exercises/37-validity-of-password/solution.hide.py @@ -1,4 +1,5 @@ import re + def valid_password(password): value = [] items=[x for x in password.split(',')] @@ -20,4 +21,6 @@ def valid_password(password): else: pass value.append(p) - return (",".join(value)) \ No newline at end of file + return (",".join(value)) + +print(valid_password("ABd1234@1,ABd1234@1,2w3E*,2We3345")) From 71cdd54a929f7d3abec94239f11c3bc56fa41bb4 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:18:49 +0100 Subject: [PATCH 23/83] Update solution.hide.py --- exercises/37-validity-of-password/solution.hide.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/37-validity-of-password/solution.hide.py b/exercises/37-validity-of-password/solution.hide.py index 17ba8386..6e47c766 100644 --- a/exercises/37-validity-of-password/solution.hide.py +++ b/exercises/37-validity-of-password/solution.hide.py @@ -1,3 +1,4 @@ +# Your code here import re def valid_password(password): From 1860b79c8844c89f035cfbcf8b71205414081df7 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:35:25 +0100 Subject: [PATCH 24/83] Update README.md --- exercises/38-sort-tuples-ascending/README.md | 38 +++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/exercises/38-sort-tuples-ascending/README.md b/exercises/38-sort-tuples-ascending/README.md index 61ca2d7a..34f3b8f8 100644 --- a/exercises/38-sort-tuples-ascending/README.md +++ b/exercises/38-sort-tuples-ascending/README.md @@ -1,23 +1,29 @@ # `38` Sort Tuples Ascending +## 📝 Instructions: -## :pencil: Instructions: -You are required to write a program to sort the (`name`, `age`, `height`) tuples by ascending order where name is `string`, age and height are numbers. The tuples are input by console. The sort criteria is: +Write a function `sort_tuples_ascending()` to sort the (`name`, `age`, `score`) tuples by ascending order where `name` is a string, `age` and `score` are numbers. The sort criteria is: -1. Sort based on name; -2. Then sort based on age; +1. Sort based on name. +2. Then sort based on age. 3. Then sort by score. The priority is that name > age > score. If the following tuples are given as input to the program: -> - `Tom,19,80` -> - `John,20,90` -> - `Jony,17,91` -> - `Jony,17,93` -> - `Jason,21,85` - -> - Then, the output of the program should be: -`[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Jason', '21', '85'), ('Tom', '19', '80')]` - -## :bulb: Hint: -In case of input data being supplied to the question, it should be assumed to be a console input. -We use itemgetter to enable multiple sort keys. \ No newline at end of file + +## 📎 Example input: + +```py +sort_tuples_ascending("Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Jason,21,85") +``` + +## 📎 Example output: + +```py +[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Jason', '21', '85'), ('Tom', '19', '80')] +``` + +## 💡 Hints: + ++ We use `itemgetter` to enable multiple sort keys. + ++ Notice that the output is a list with tuples inside. From d40a9ad8caef492217bad8e697636f09c2f7b8c3 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:49:07 +0100 Subject: [PATCH 25/83] Update solution.hide.py --- exercises/38-sort-tuples-ascending/solution.hide.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/exercises/38-sort-tuples-ascending/solution.hide.py b/exercises/38-sort-tuples-ascending/solution.hide.py index e1833148..62a5f6fe 100644 --- a/exercises/38-sort-tuples-ascending/solution.hide.py +++ b/exercises/38-sort-tuples-ascending/solution.hide.py @@ -1,5 +1,10 @@ -from operator import itemgetter, attrgetter +from operator import itemgetter + def sort_tuples_ascending(tuples): - l = [] - l.append(tuple(tuples.split(","))) - return (sorted(l, key=itemgetter(0,1,2))) + tuple_list = [tuple(item.split(',')) for item in tuples.split()] + + sorted_list = sorted(tuple_list, key=itemgetter(0, 1, 2)) + + return sorted_list + +print(sort_tuples_ascending("Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Jason,21,85")) From dd74f207a418f22368060486cfd1595a8789bce5 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:49:26 +0100 Subject: [PATCH 26/83] Update solution.hide.py --- exercises/38-sort-tuples-ascending/solution.hide.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/38-sort-tuples-ascending/solution.hide.py b/exercises/38-sort-tuples-ascending/solution.hide.py index 62a5f6fe..c4bcd31e 100644 --- a/exercises/38-sort-tuples-ascending/solution.hide.py +++ b/exercises/38-sort-tuples-ascending/solution.hide.py @@ -1,5 +1,6 @@ from operator import itemgetter +# Your code here def sort_tuples_ascending(tuples): tuple_list = [tuple(item.split(',')) for item in tuples.split()] From 34f92c0f0e4c3fc03b9318e254c2872bf9caeab2 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:49:33 +0100 Subject: [PATCH 27/83] Update app.py --- exercises/38-sort-tuples-ascending/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exercises/38-sort-tuples-ascending/app.py b/exercises/38-sort-tuples-ascending/app.py index e69de29b..5fa288aa 100644 --- a/exercises/38-sort-tuples-ascending/app.py +++ b/exercises/38-sort-tuples-ascending/app.py @@ -0,0 +1,3 @@ +from operator import itemgetter + +# Your code here From 3fb74206cf5afb7275c43570414af621b3324dfc Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:49:38 +0100 Subject: [PATCH 28/83] Update app.py From e02e57e378b71c157504fa66da92ecdb3f126329 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:50:26 +0100 Subject: [PATCH 29/83] Update README.md --- exercises/38-sort-tuples-ascending/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/38-sort-tuples-ascending/README.md b/exercises/38-sort-tuples-ascending/README.md index 34f3b8f8..0cc419a4 100644 --- a/exercises/38-sort-tuples-ascending/README.md +++ b/exercises/38-sort-tuples-ascending/README.md @@ -7,8 +7,8 @@ Write a function `sort_tuples_ascending()` to sort the (`name`, `age`, `score`) 1. Sort based on name. 2. Then sort based on age. 3. Then sort by score. + The priority is that name > age > score. -If the following tuples are given as input to the program: ## 📎 Example input: From fce6fca0cb04b4a21a1ec8abeebe9432a233af71 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:51:55 +0100 Subject: [PATCH 30/83] Update README.md --- exercises/38-sort-tuples-ascending/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/38-sort-tuples-ascending/README.md b/exercises/38-sort-tuples-ascending/README.md index 0cc419a4..8a8fa687 100644 --- a/exercises/38-sort-tuples-ascending/README.md +++ b/exercises/38-sort-tuples-ascending/README.md @@ -2,7 +2,7 @@ ## 📝 Instructions: -Write a function `sort_tuples_ascending()` to sort the (`name`, `age`, `score`) tuples by ascending order where `name` is a string, `age` and `score` are numbers. The sort criteria is: +Write a function `sort_tuples_ascending()` to sort the (`name`, `age`, `score`) tuples by ascending order where `name`, `age` and `score` are all strings. The sort criteria is: 1. Sort based on name. 2. Then sort based on age. From ce2a099408c6afafd4aa8b131406628154556d1c Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:00:53 +0100 Subject: [PATCH 31/83] Update README.es.md --- .../38-sort-tuples-ascending/README.es.md | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/exercises/38-sort-tuples-ascending/README.es.md b/exercises/38-sort-tuples-ascending/README.es.md index bae01186..e3717aff 100644 --- a/exercises/38-sort-tuples-ascending/README.es.md +++ b/exercises/38-sort-tuples-ascending/README.es.md @@ -1,2 +1,28 @@ # `38` Sort Tuples Ascending -Debe escribir un programa para ordenar las tuplas (nombre, edad, altura) por orden ascendente donde el nombre es `string`, la edad y la altura son `números`. + +## 📝 Instrucciones: + +Escribe una función llamada `sort_tuples_ascending()` para ordenar las tuplas (`name`, `age`, `score`) en orden ascendente, donde `name`, `age` y `score` son strings. El criterio de orden es: + +1. Ordenar según el nombre. +2. Luego, ordenar según la edad. +3. Después, ordenar por puntuación. +La prioridad es que name > age > score. + +## 📎 Ejemplo de entrada: + +```py +sort_tuples_ascending("Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Jason,21,85") +``` + +## 📎 Ejemplo de salida: + +```py +[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Jason', '21', '85'), ('Tom', '19', '80')] +``` + +## 💡 Hints: + ++ Utilizamos `itemgetter` para habilitar múltiples claves de orden. + ++ Observa que la salida es una lista con tuplas en su interior. From 66028ab704940ef7112eca95931c561a47e34fb9 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:01:03 +0100 Subject: [PATCH 32/83] Update README.md --- exercises/38-sort-tuples-ascending/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/38-sort-tuples-ascending/README.md b/exercises/38-sort-tuples-ascending/README.md index 8a8fa687..0d19c3fc 100644 --- a/exercises/38-sort-tuples-ascending/README.md +++ b/exercises/38-sort-tuples-ascending/README.md @@ -2,7 +2,7 @@ ## 📝 Instructions: -Write a function `sort_tuples_ascending()` to sort the (`name`, `age`, `score`) tuples by ascending order where `name`, `age` and `score` are all strings. The sort criteria is: +Write a function `sort_tuples_ascending()` to sort the (`name`, `age`, `score`) tuples by ascending order, where `name`, `age` and `score` are all strings. The sort criteria is: 1. Sort based on name. 2. Then sort based on age. From fbef8553030bc89506d7689d4695d1e7c452dacb Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:01:27 +0100 Subject: [PATCH 33/83] Update README.es.md --- exercises/38-sort-tuples-ascending/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/38-sort-tuples-ascending/README.es.md b/exercises/38-sort-tuples-ascending/README.es.md index e3717aff..5ff9cae2 100644 --- a/exercises/38-sort-tuples-ascending/README.es.md +++ b/exercises/38-sort-tuples-ascending/README.es.md @@ -21,7 +21,7 @@ sort_tuples_ascending("Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Jason,21,85") [('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Jason', '21', '85'), ('Tom', '19', '80')] ``` -## 💡 Hints: +## 💡 Pistas: + Utilizamos `itemgetter` para habilitar múltiples claves de orden. From d82e4bb9296123e4e935f323de4c4505bd9d50c7 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:13:44 +0100 Subject: [PATCH 34/83] Update test.py --- exercises/38-sort-tuples-ascending/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/38-sort-tuples-ascending/test.py b/exercises/38-sort-tuples-ascending/test.py index c8a4b30a..77ae2d6b 100644 --- a/exercises/38-sort-tuples-ascending/test.py +++ b/exercises/38-sort-tuples-ascending/test.py @@ -14,4 +14,4 @@ def etest_expected_output(capsys, app): @pytest.mark.it('The solution should work with other entries') def test_another_entry(capsys, app): - app.sort_tuples_ascending("Martin,23,30 Tomas,25,27") == [('Martin', '23', '30', 'Tomas', '25', '27')] + app.sort_tuples_ascending("Martin,23,30 Tomas,25,27") == [('Martin', '23', '30'), ('Tomas', '25', '27')] From 27ce1a19bf05f7dc9212eee74da9d0bbf9bb801c Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:14:08 +0100 Subject: [PATCH 35/83] Update README.es.md --- exercises/38-sort-tuples-ascending/README.es.md | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/38-sort-tuples-ascending/README.es.md b/exercises/38-sort-tuples-ascending/README.es.md index 5ff9cae2..6fa33e9e 100644 --- a/exercises/38-sort-tuples-ascending/README.es.md +++ b/exercises/38-sort-tuples-ascending/README.es.md @@ -7,6 +7,7 @@ Escribe una función llamada `sort_tuples_ascending()` para ordenar las tuplas ( 1. Ordenar según el nombre. 2. Luego, ordenar según la edad. 3. Después, ordenar por puntuación. + La prioridad es que name > age > score. ## 📎 Ejemplo de entrada: From 3fd9bd83c1b4e993c15fb7becc57309c3acf76b6 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:26:02 +0100 Subject: [PATCH 36/83] Update README.md --- exercises/39-class-that-iterates/README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/exercises/39-class-that-iterates/README.md b/exercises/39-class-that-iterates/README.md index ea0f818e..d869df91 100644 --- a/exercises/39-class-that-iterates/README.md +++ b/exercises/39-class-that-iterates/README.md @@ -1,4 +1,9 @@ -Define a class with a generator which can iterate the numbers, which are divisible by 7, between a given range 0 and n. +# `38` Class that iterates -Hints: -Consider use yield \ No newline at end of file +## 📝 Instructions: + +1. Define a class with a generator that can iterate the numbers that are divisible by 7, between a given range `0` and `n`. + +## 💡 Hint: + ++ Consider using `yield`. From 8563d941946f6847d3a07137c983bb4ff80a096f Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:26:12 +0100 Subject: [PATCH 37/83] Update app.py --- exercises/39-class-that-iterates/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/39-class-that-iterates/app.py b/exercises/39-class-that-iterates/app.py index e69de29b..a51f0856 100644 --- a/exercises/39-class-that-iterates/app.py +++ b/exercises/39-class-that-iterates/app.py @@ -0,0 +1 @@ +# Your code here From 09ecb609f0e9724fcbf8726082a22c545ab3d525 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:40:18 +0100 Subject: [PATCH 38/83] Create README.es.md --- exercises/39-class-that-iterates/README.es.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 exercises/39-class-that-iterates/README.es.md diff --git a/exercises/39-class-that-iterates/README.es.md b/exercises/39-class-that-iterates/README.es.md new file mode 100644 index 00000000..293c264d --- /dev/null +++ b/exercises/39-class-that-iterates/README.es.md @@ -0,0 +1,9 @@ +# `39` Class that iterates + +## 📝 Instrucciones: + +Define una clase con un generador que pueda iterar los números que son divisibles por 7 en un rango dado de `0` a `n`. + +## 💡 Pista: + ++ Considera usar `yield`. From e5de8702b53080d89e042719f55ad5002be4db63 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:40:33 +0100 Subject: [PATCH 39/83] Update README.md --- exercises/39-class-that-iterates/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/39-class-that-iterates/README.md b/exercises/39-class-that-iterates/README.md index d869df91..c4f4fb46 100644 --- a/exercises/39-class-that-iterates/README.md +++ b/exercises/39-class-that-iterates/README.md @@ -1,4 +1,4 @@ -# `38` Class that iterates +# `39` Class that iterates ## 📝 Instructions: From ec05b784d5637ea7a2cdeb763f363395f420dde1 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:40:56 +0100 Subject: [PATCH 40/83] Update README.es.md --- exercises/39-class-that-iterates/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/39-class-that-iterates/README.es.md b/exercises/39-class-that-iterates/README.es.md index 293c264d..8e743c97 100644 --- a/exercises/39-class-that-iterates/README.es.md +++ b/exercises/39-class-that-iterates/README.es.md @@ -2,7 +2,7 @@ ## 📝 Instrucciones: -Define una clase con un generador que pueda iterar los números que son divisibles por 7 en un rango dado de `0` a `n`. +1. Define una clase con un generador que pueda iterar los números que son divisibles por 7 en un rango dado de `0` a `n`. ## 💡 Pista: From 9a714981700bbb7070bc3f49b8c61374476f14a8 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:58:31 +0100 Subject: [PATCH 41/83] Update README.md --- exercises/40-compute-robot-distance/README.md | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/exercises/40-compute-robot-distance/README.md b/exercises/40-compute-robot-distance/README.md index 0a690480..fe600c88 100644 --- a/exercises/40-compute-robot-distance/README.md +++ b/exercises/40-compute-robot-distance/README.md @@ -1,18 +1,24 @@ -A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following: -UP 5 -DOWN 3 -LEFT 3 -RIGHT 2 -¡­ -The numbers after the direction are steps. Please write a program to compute the distance from current position after a sequence of movement and original point. If the distance is a float, then just print the nearest integer. -Example: -If the following tuples are given as input to the program: -UP 5 -DOWN 3 -LEFT 3 -RIGHT 2 -Then, the output of the program should be: -2 +# `40` Compute robot distance + +## 📝 Instructions: + +A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with given steps. The trace of robot movement is shown as the following: + ++ UP 5 ++ DOWN 3 ++ LEFT 3 ++ RIGHT 2 + +The numbers after the direction are steps. Please write a program to compute the distance from the current position after a sequence of movements from the original point. If the distance is a float, then just print the nearest integer. -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. \ No newline at end of file +## 📎 Example input: + +```py +compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2") +``` + +## 📎 Example output: + +```py +2 +``` From 543a5ab4ed23c5e7bf13bca840db52723243bfb6 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:00:01 +0100 Subject: [PATCH 42/83] Update app.py --- exercises/40-compute-robot-distance/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/40-compute-robot-distance/app.py b/exercises/40-compute-robot-distance/app.py index e69de29b..a51f0856 100644 --- a/exercises/40-compute-robot-distance/app.py +++ b/exercises/40-compute-robot-distance/app.py @@ -0,0 +1 @@ +# Your code here From 07ec6c3af220e9920f99478812a58f281bd3cf32 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:01:15 +0100 Subject: [PATCH 43/83] Update solution.hide.py --- exercises/40-compute-robot-distance/solution.hide.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exercises/40-compute-robot-distance/solution.hide.py b/exercises/40-compute-robot-distance/solution.hide.py index f32439ae..17af8bcd 100644 --- a/exercises/40-compute-robot-distance/solution.hide.py +++ b/exercises/40-compute-robot-distance/solution.hide.py @@ -1,4 +1,6 @@ +# Your code here import math + def compute_robot_distance(props): pos = [0,0] new_prop = props.split(" ") @@ -14,4 +16,5 @@ def compute_robot_distance(props): else: None return (int(round(math.sqrt(pos[1]**2+pos[0]**2)))) - \ No newline at end of file + +print(compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2")) From e45ddb99bfe3b731f450099d2fd320bb079ae8a8 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:13:54 +0100 Subject: [PATCH 44/83] Update README.md --- exercises/40-compute-robot-distance/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/40-compute-robot-distance/README.md b/exercises/40-compute-robot-distance/README.md index fe600c88..0cd91dc0 100644 --- a/exercises/40-compute-robot-distance/README.md +++ b/exercises/40-compute-robot-distance/README.md @@ -9,7 +9,7 @@ A robot moves in a plane starting from the original point (0,0). The robot can m + LEFT 3 + RIGHT 2 -The numbers after the direction are steps. Please write a program to compute the distance from the current position after a sequence of movements from the original point. If the distance is a float, then just print the nearest integer. +The numbers after the direction are steps. Please write a program named `compute_robot_distance()` to compute the distance from the current position after a sequence of movements from the original point. If the distance is a float, then just print the nearest integer. ## 📎 Example input: From 27c687ec124869618cf455dd9922db8e09490233 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:15:36 +0100 Subject: [PATCH 45/83] Create README.es.md --- .../40-compute-robot-distance/README.es.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 exercises/40-compute-robot-distance/README.es.md diff --git a/exercises/40-compute-robot-distance/README.es.md b/exercises/40-compute-robot-distance/README.es.md new file mode 100644 index 00000000..e62a7ac3 --- /dev/null +++ b/exercises/40-compute-robot-distance/README.es.md @@ -0,0 +1,24 @@ +# `40` Compute robot distance + +## 📝 Instrucciones: + +Un robot se mueve en un plano comenzando desde el punto de inicio (0,0). El robot puede moverse hacia ARRIBA (UP), ABAJO (DOWN), IZQUIERDA (LEFT) y DERECHA (RIGHT) con pasos dados por parámetro. La traza del movimiento del robot se muestra de la siguiente manera: + ++ UP 5 ++ DOWN 3 ++ LEFT 3 ++ RIGHT 2 + +Los números después de la dirección son los pasos. Por favor, escribe un programa llamado `compute_robot_distance()` para calcular la distancia final después de una secuencia de movimientos desde el punto original. Si la distancia es un número decimal, simplemente imprime el entero más cercano. + +## 📎 Ejemplo de entrada: + +```py +compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2") +``` + +## 📎 Ejemplo de salida: + +```py +2 +``` From 536cded5f81050c02730547083591a7c5a341f97 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:15:38 +0100 Subject: [PATCH 46/83] Update README.md --- exercises/40-compute-robot-distance/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/40-compute-robot-distance/README.md b/exercises/40-compute-robot-distance/README.md index 0cd91dc0..4d2340ee 100644 --- a/exercises/40-compute-robot-distance/README.md +++ b/exercises/40-compute-robot-distance/README.md @@ -9,7 +9,7 @@ A robot moves in a plane starting from the original point (0,0). The robot can m + LEFT 3 + RIGHT 2 -The numbers after the direction are steps. Please write a program named `compute_robot_distance()` to compute the distance from the current position after a sequence of movements from the original point. If the distance is a float, then just print the nearest integer. +The numbers after the direction are steps. Please write a program named `compute_robot_distance()` to compute the final distance after a sequence of movements from the original point. If the distance is a float, then just print the nearest integer. ## 📎 Example input: From 1fff9c727795607b69f00401c20e883b3abda2ef Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:17:18 +0100 Subject: [PATCH 47/83] Update test.py --- exercises/40-compute-robot-distance/test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/40-compute-robot-distance/test.py b/exercises/40-compute-robot-distance/test.py index 33cc55e2..d976852f 100644 --- a/exercises/40-compute-robot-distance/test.py +++ b/exercises/40-compute-robot-distance/test.py @@ -5,7 +5,6 @@ def test_function_existence(capsys, app): assert app.compute_robot_distance - @pytest.mark.it('The function should return the expected output') def test_expected_output(capsys, app): assert app.compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2") == 2 From 2637b7925f0f9b3bee8f0cee26252ca4f052d5de Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:23:01 +0100 Subject: [PATCH 48/83] Update README.md --- exercises/41-frequency-of-words/README.md | 41 ++++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/exercises/41-frequency-of-words/README.md b/exercises/41-frequency-of-words/README.md index 0b1940a1..8b3a640c 100644 --- a/exercises/41-frequency-of-words/README.md +++ b/exercises/41-frequency-of-words/README.md @@ -1,18 +1,27 @@ -Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically. -Suppose the following input is supplied to the program: +# `41` Frequency of words + +## 📝 Instructions: + +1. Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically. + +## 📎 Example input: + +```text New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3. -Then, the output should be: -2:2 -3.:1 -3?:1 -New:1 -Python:5 -Read:1 -and:1 -between:1 -choosing:1 -or:2 -to:1 +``` + +## 📎 Example output: -Hints -In case of input data being supplied to the question, it should be assumed to be a console input. \ No newline at end of file +```py +2: 2 +3.: 1 +3?: 1 +New: 1 +Python: 5 +Read: 1 +and: 1 +between: 1 +choosing: 1 +or: 2 +to: 1 +``` From 087d9ba72c57ab1d0e451b68fe5bb2a3fde16784 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:24:07 +0100 Subject: [PATCH 49/83] Update app.py --- exercises/41-frequency-of-words/app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/41-frequency-of-words/app.py b/exercises/41-frequency-of-words/app.py index e69de29b..a51f0856 100644 --- a/exercises/41-frequency-of-words/app.py +++ b/exercises/41-frequency-of-words/app.py @@ -0,0 +1 @@ +# Your code here From c7bb7ada9dec67857a8255cf4e4c34d0f19b0659 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:44:47 +0100 Subject: [PATCH 50/83] Create README.es.md --- exercises/41-frequency-of-words/README.es.md | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 exercises/41-frequency-of-words/README.es.md diff --git a/exercises/41-frequency-of-words/README.es.md b/exercises/41-frequency-of-words/README.es.md new file mode 100644 index 00000000..8280156e --- /dev/null +++ b/exercises/41-frequency-of-words/README.es.md @@ -0,0 +1,27 @@ +# `41` Frequency of words + +## 📝 Instrucciones: + +1. Escribe un programa para calcular la frecuencia de las palabras a partir de la entrada. La salida debe mostrarse después de ordenar las claves alfanuméricamente. + +## 📎 Ejemplo de entrada: + +```text +"New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3." +``` + +## 📎 Ejemplo de salida: + +```py +2: 2 +3.: 1 +3?: 1 +New: 1 +Python: 5 +Read: 1 +and: 1 +between: 1 +choosing: 1 +or: 2 +to: 1 +``` From 155e5c68f3bb7f9d38fbcb7d933eac1d3f278503 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:44:58 +0100 Subject: [PATCH 51/83] Update README.md --- exercises/41-frequency-of-words/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/41-frequency-of-words/README.md b/exercises/41-frequency-of-words/README.md index 8b3a640c..443e8204 100644 --- a/exercises/41-frequency-of-words/README.md +++ b/exercises/41-frequency-of-words/README.md @@ -6,8 +6,8 @@ ## 📎 Example input: -```text -New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3. +```py +"New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3." ``` ## 📎 Example output: From 926d7f894e31f969f67c6b758bb64a4ee3e793fc Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:47:10 +0100 Subject: [PATCH 52/83] Update README.es.md --- exercises/41-frequency-of-words/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/41-frequency-of-words/README.es.md b/exercises/41-frequency-of-words/README.es.md index 8280156e..2bb286c2 100644 --- a/exercises/41-frequency-of-words/README.es.md +++ b/exercises/41-frequency-of-words/README.es.md @@ -6,7 +6,7 @@ ## 📎 Ejemplo de entrada: -```text +```py "New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3." ``` From 042bc62f429c66e503801fa1793069c509877f31 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 02:12:07 +0100 Subject: [PATCH 53/83] Update solution.hide.py --- .../solution.hide.py | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/exercises/35-square-each-odd-number/solution.hide.py b/exercises/35-square-each-odd-number/solution.hide.py index 15da0957..2a42fed8 100644 --- a/exercises/35-square-each-odd-number/solution.hide.py +++ b/exercises/35-square-each-odd-number/solution.hide.py @@ -1,8 +1,26 @@ # Your code here -def square_odd_numbers(numbers): - number_list = [int(num) for num in numbers.split(',')] - squared_odd_numbers = [num**2 for num in number_list if num % 2 != 0] +def square_odd_numbers(numbers_str): + numbers_list = numbers_str.split(',') + squared_odd_numbers = [] + + for num_str in numbers_list: + if num_str.isdigit(): + num = int(num_str) + + if num % 2 != 0: + squared_odd_numbers.append(num**2) return squared_odd_numbers print(square_odd_numbers("1,2,3,4,5,6,7")) + + +### SOLUTION 2 ### (List Comprehension) + +# def square_odd_numbers(numbers): +# number_list = [int(num) for num in numbers.split(',')] +# squared_odd_numbers = [num**2 for num in number_list if num % 2 != 0] + +# return squared_odd_numbers + +# print(square_odd_numbers("1,2,3,4,5,6,7")) From 64236e975a3206c57a28ea70d0e7c1caa13b9feb Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 02:44:20 +0100 Subject: [PATCH 54/83] Update README.es.md --- exercises/37-validity-of-password/README.es.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/37-validity-of-password/README.es.md b/exercises/37-validity-of-password/README.es.md index b6459b4e..18994aa2 100644 --- a/exercises/37-validity-of-password/README.es.md +++ b/exercises/37-validity-of-password/README.es.md @@ -11,18 +11,18 @@ Un sitio web requiere que los usuarios ingresen un nombre de usuario y una contr 5. Longitud mínima de la contraseña: 6. 6. Longitud máxima de la contraseña: 12. -Tu programa debería aceptar una secuencia de contraseñas separadas por comas y verificarlas según los criterios anteriores. Las contraseñas que cumplan con los criterios deben imprimirse, cada una separada por una coma. +Tu programa debe aceptar una contraseña y verificarla según los criterios anteriores. Si la contraseña es validada correctamente, la función devuelve el siguiente string `"Valid password"`, de lo contrario devuelve `"Invalid password. Please try again"` ## 📎 Ejemplo de entrada: ```py -valid_password("ABd1234@1,a F1#,2w3E*,2We3345") +valid_password("ABd1234@1") ``` ## 📎 Ejemplo de salida: -```text -ABd1234@1 +```py +"Valid password" ``` ## 💡 Pistas: From 436732c67bef26ff7b3026d870cc1a24d4b09aa1 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 02:47:20 +0100 Subject: [PATCH 55/83] Update README.es.md --- exercises/37-validity-of-password/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/37-validity-of-password/README.es.md b/exercises/37-validity-of-password/README.es.md index 18994aa2..038e3b8b 100644 --- a/exercises/37-validity-of-password/README.es.md +++ b/exercises/37-validity-of-password/README.es.md @@ -11,7 +11,7 @@ Un sitio web requiere que los usuarios ingresen un nombre de usuario y una contr 5. Longitud mínima de la contraseña: 6. 6. Longitud máxima de la contraseña: 12. -Tu programa debe aceptar una contraseña y verificarla según los criterios anteriores. Si la contraseña es validada correctamente, la función devuelve el siguiente string `"Valid password"`, de lo contrario devuelve `"Invalid password. Please try again"` +Tu programa debe aceptar una contraseña y verificarla según los criterios anteriores. Si la contraseña es validada correctamente, la función devuelve el siguiente string `"Valid password"`, de lo contrario devuelve `"Invalid password. Please try again"`. ## 📎 Ejemplo de entrada: From 2c2e41d00e59f6f63b947cfb141ce8848dd25896 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 02:50:10 +0100 Subject: [PATCH 56/83] Update README.md --- exercises/37-validity-of-password/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/37-validity-of-password/README.md b/exercises/37-validity-of-password/README.md index d87f51f2..f5ff2c52 100644 --- a/exercises/37-validity-of-password/README.md +++ b/exercises/37-validity-of-password/README.md @@ -11,18 +11,18 @@ A website requires the users to input a username and password to register. Write 5. Minimum length of password: 6. 6. Maximum length of password: 12. -Your program should accept a sequence of comma-separated passwords and check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. +Your program should accept a password and verify it according to the previous criteria. If the password is successfully validated, the function returns the following string `"Valid password"`. Otherwise, it returns `"Invalid password. Please try again."`. ## 📎 Example input: ```py -valid_password("ABd1234@1,a F1#,2w3E*,2We3345") +valid_password("ABd1234@1") ``` ## 📎 Example output: ```text -ABd1234@1 +Valid password ``` ## 💡 Hints: From 48b138f5e713455773b4b65afd782391077140ee Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 02:50:24 +0100 Subject: [PATCH 57/83] Update README.md --- exercises/37-validity-of-password/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/37-validity-of-password/README.md b/exercises/37-validity-of-password/README.md index f5ff2c52..8b2aa6cd 100644 --- a/exercises/37-validity-of-password/README.md +++ b/exercises/37-validity-of-password/README.md @@ -21,8 +21,8 @@ valid_password("ABd1234@1") ## 📎 Example output: -```text -Valid password +```py +"Valid password" ``` ## 💡 Hints: From 962eff48e7530bc69f99a524b6652936e670e5f7 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 02:53:02 +0100 Subject: [PATCH 58/83] Update README.md --- exercises/37-validity-of-password/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/37-validity-of-password/README.md b/exercises/37-validity-of-password/README.md index 8b2aa6cd..0e2329f8 100644 --- a/exercises/37-validity-of-password/README.md +++ b/exercises/37-validity-of-password/README.md @@ -11,7 +11,7 @@ A website requires the users to input a username and password to register. Write 5. Minimum length of password: 6. 6. Maximum length of password: 12. -Your program should accept a password and verify it according to the previous criteria. If the password is successfully validated, the function returns the following string `"Valid password"`. Otherwise, it returns `"Invalid password. Please try again."`. +Your program should accept a password and verify it according to the previous criteria. If the password is successfully validated, the function returns the following string `"Valid password"`. Otherwise, it returns `"Invalid password. Please try again"`. ## 📎 Example input: From 041dc4b16a3f4e75ddc61ae1c421a26c3e8c267d Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:11:15 +0100 Subject: [PATCH 59/83] Update solution.hide.py --- .../37-validity-of-password/solution.hide.py | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/exercises/37-validity-of-password/solution.hide.py b/exercises/37-validity-of-password/solution.hide.py index 6e47c766..dff22c64 100644 --- a/exercises/37-validity-of-password/solution.hide.py +++ b/exercises/37-validity-of-password/solution.hide.py @@ -2,26 +2,35 @@ import re def valid_password(password): - value = [] - items=[x for x in password.split(',')] - for p in items: - if len(p)<6 or len(p)>12: - continue - else: - pass - if not re.search("[a-z]",p): - continue - elif not re.search("[0-9]",p): - continue - elif not re.search("[A-Z]",p): - continue - elif not re.search("[$#@]",p): - continue - elif re.search("\s",p): - continue - else: - pass - value.append(p) - return (",".join(value)) - -print(valid_password("ABd1234@1,ABd1234@1,2w3E*,2We3345")) + if len(password) < 6 or len(password) > 12: + return "Invalid password. Please try again" + + if not re.search("[a-z]", password): + return "Invalid password. Please try again" + elif not re.search("[0-9]", password): + return "Invalid password. Please try again" + elif not re.search("[A-Z]", password): + return "Invalid password. Please try again" + elif not re.search("[$#@]", password): + return "Invalid password. Please try again" + elif re.search("\s", password): + return "Invalid password. Please try again" + + return "Valid password" + +print(valid_password("ABd1234@1")) + + +### SOLUTION 2 ### + +# import re + +# def valid_password(password): +# pattern = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[$#@]).{6,12}$') + +# if pattern.match(password): +# return "Valid password" +# else: +# return "Invalid password. Please try again" + +# print(valid_password("ABd1234@1")) From c6a52ad0f8351ca35506afb5902e850db79b18b9 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:13:15 +0100 Subject: [PATCH 60/83] Update test.py --- exercises/37-validity-of-password/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/37-validity-of-password/test.py b/exercises/37-validity-of-password/test.py index 741504a2..2ceb3210 100644 --- a/exercises/37-validity-of-password/test.py +++ b/exercises/37-validity-of-password/test.py @@ -8,12 +8,12 @@ def test_function_existence(capsys, app): @pytest.mark.it('The function should return the expected output') def test_expected_output(capsys, app): - assert app.valid_password("ABd1234@1,a F1#,2w3E*,2We3345") == "ABd1234@1" + assert app.valid_password("ABd1234@1") == "Valid password" @pytest.mark.it('Your solution should work as expected for valid passwords') def test_expected_another_output(capsys, app): - assert app.valid_password("Lmd4567@2,a F1#,2w3E*,2We3345") == "Lmd4567@2" + assert app.valid_password("Lmd4567@2") == "Valid password" @pytest.mark.it('Your solution should work as expected when there is no valid password input') def test_expected_output_no_valid_entries(capsys, app): - assert app.valid_password("ABd12,a F1#,2w3E*,2We3345") == "" \ No newline at end of file + assert app.valid_password("ABd12") == "Invalid password. Please try again" From e8c667b5d1aceb8b9cab664f0bf9f9b5b4dc0224 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:35:25 +0100 Subject: [PATCH 61/83] Update README.md --- exercises/38-sort-tuples-ascending/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/38-sort-tuples-ascending/README.md b/exercises/38-sort-tuples-ascending/README.md index 0d19c3fc..4ccc6050 100644 --- a/exercises/38-sort-tuples-ascending/README.md +++ b/exercises/38-sort-tuples-ascending/README.md @@ -13,13 +13,13 @@ The priority is that name > age > score. ## 📎 Example input: ```py -sort_tuples_ascending("Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Jason,21,85") +sort_tuples_ascending(['Tom,19,80', 'John,20,90', 'Jony,17,91', 'Jony,17,93', 'Jason,21,85']) ``` ## 📎 Example output: ```py -[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Jason', '21', '85'), ('Tom', '19', '80')] +[('Jason', '21', '85'), ('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Tom', '19', '80')] ``` ## 💡 Hints: From 3244157bfd3356b83be150e958abee56aa1baff1 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:35:33 +0100 Subject: [PATCH 62/83] Update test.py --- exercises/38-sort-tuples-ascending/test.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/exercises/38-sort-tuples-ascending/test.py b/exercises/38-sort-tuples-ascending/test.py index 77ae2d6b..f8fefa6e 100644 --- a/exercises/38-sort-tuples-ascending/test.py +++ b/exercises/38-sort-tuples-ascending/test.py @@ -2,16 +2,23 @@ path = os.path.dirname(os.path.abspath(__file__))+'/app.py' - @pytest.mark.it('The function sort_tuples_ascending must exist') def test_function_existence(capsys, app): assert app.sort_tuples_ascending - @pytest.mark.it('The function should return the expected output') -def etest_expected_output(capsys, app): - app.sort_tuples_ascending("Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Json,21,85") == [('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')] +def test_expected_output(capsys, app): + assert app.sort_tuples_ascending([ + 'Tom,19,80', + 'John,20,90', + 'Jony,17,91', + 'Jony,17,93', + 'Jason,21,85' + ]) == [('Jason', '21', '85'), ('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Tom', '19', '80')] @pytest.mark.it('The solution should work with other entries') def test_another_entry(capsys, app): - app.sort_tuples_ascending("Martin,23,30 Tomas,25,27") == [('Martin', '23', '30'), ('Tomas', '25', '27')] + assert app.sort_tuples_ascending([ + 'Martin,23,30', + 'Tomas,25,27' + ]) == [('Martin', '23', '30'), ('Tomas', '25', '27')] From c442c87137fca3e5de14d15508bf2c1527e99306 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:35:59 +0100 Subject: [PATCH 63/83] Update solution.hide.py --- .../38-sort-tuples-ascending/solution.hide.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/exercises/38-sort-tuples-ascending/solution.hide.py b/exercises/38-sort-tuples-ascending/solution.hide.py index c4bcd31e..20c10a3c 100644 --- a/exercises/38-sort-tuples-ascending/solution.hide.py +++ b/exercises/38-sort-tuples-ascending/solution.hide.py @@ -1,11 +1,20 @@ from operator import itemgetter # Your code here -def sort_tuples_ascending(tuples): - tuple_list = [tuple(item.split(',')) for item in tuples.split()] +def sort_tuples_ascending(data): + tuples_list = [tuple(entry.split(',')) for entry in data] - sorted_list = sorted(tuple_list, key=itemgetter(0, 1, 2)) + sorted_tuples = sorted(tuples_list, key=itemgetter(0, 1, 2)) - return sorted_list + return sorted_tuples -print(sort_tuples_ascending("Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Jason,21,85")) +example_input = [ + 'Tom,19,80', + 'John,20,90', + 'Jony,17,91', + 'Jony,17,93', + 'Jason,21,85' +] + +result = sort_tuples_ascending(example_input) +print(result) From 8677488af2e53052c1c914ccfd17778d30dd8b73 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:38:39 +0100 Subject: [PATCH 64/83] Update README.es.md --- exercises/38-sort-tuples-ascending/README.es.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/38-sort-tuples-ascending/README.es.md b/exercises/38-sort-tuples-ascending/README.es.md index 6fa33e9e..41888717 100644 --- a/exercises/38-sort-tuples-ascending/README.es.md +++ b/exercises/38-sort-tuples-ascending/README.es.md @@ -8,12 +8,12 @@ Escribe una función llamada `sort_tuples_ascending()` para ordenar las tuplas ( 2. Luego, ordenar según la edad. 3. Después, ordenar por puntuación. -La prioridad es que name > age > score. +La prioridad es `name` > `age` > `score`. ## 📎 Ejemplo de entrada: ```py -sort_tuples_ascending("Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Jason,21,85") +sort_tuples_ascending(['Tom,19,80', 'John,20,90', 'Jony,17,91', 'Jony,17,93', 'Jason,21,85']) ``` ## 📎 Ejemplo de salida: From ebb3428972c1f11ac17c34650690f07e009b6b82 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:39:36 +0100 Subject: [PATCH 65/83] Update README.md --- exercises/38-sort-tuples-ascending/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/38-sort-tuples-ascending/README.md b/exercises/38-sort-tuples-ascending/README.md index 4ccc6050..d2e8a704 100644 --- a/exercises/38-sort-tuples-ascending/README.md +++ b/exercises/38-sort-tuples-ascending/README.md @@ -8,7 +8,7 @@ Write a function `sort_tuples_ascending()` to sort the (`name`, `age`, `score`) 2. Then sort based on age. 3. Then sort by score. -The priority is that name > age > score. +The priority is `name` > `age` > `score`. ## 📎 Example input: From bf6d3b64f8235a36b1125ff49b9a00448c99bcb4 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 04:10:45 +0100 Subject: [PATCH 66/83] Update solution.hide.py --- .../39-class-that-iterates/solution.hide.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/exercises/39-class-that-iterates/solution.hide.py b/exercises/39-class-that-iterates/solution.hide.py index ddddb1db..acd55ff4 100644 --- a/exercises/39-class-that-iterates/solution.hide.py +++ b/exercises/39-class-that-iterates/solution.hide.py @@ -1,10 +1,15 @@ -def putNumbers(n): - i = 0 - while i Date: Mon, 1 Jan 2024 04:31:54 +0100 Subject: [PATCH 67/83] Update README.md --- exercises/39-class-that-iterates/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/39-class-that-iterates/README.md b/exercises/39-class-that-iterates/README.md index c4f4fb46..ceb6a0f7 100644 --- a/exercises/39-class-that-iterates/README.md +++ b/exercises/39-class-that-iterates/README.md @@ -2,8 +2,8 @@ ## 📝 Instructions: -1. Define a class with a generator that can iterate the numbers that are divisible by 7, between a given range `0` and `n`. +1. Define a class with a generator function that can iterate the numbers that are divisible by 7, between a given range `0` and `n`. ## 💡 Hint: -+ Consider using `yield`. ++ Read about generator functions and `yield`: https://sentry.io/answers/python-yield-keyword/ From 142bbf9a18ca2adadfb54d9f22061871df8e1b92 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 04:32:57 +0100 Subject: [PATCH 68/83] Update README.es.md --- exercises/39-class-that-iterates/README.es.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/39-class-that-iterates/README.es.md b/exercises/39-class-that-iterates/README.es.md index 8e743c97..a283641d 100644 --- a/exercises/39-class-that-iterates/README.es.md +++ b/exercises/39-class-that-iterates/README.es.md @@ -2,8 +2,8 @@ ## 📝 Instrucciones: -1. Define una clase con un generador que pueda iterar los números que son divisibles por 7 en un rango dado de `0` a `n`. +1. Define una clase con una función generadora que pueda iterar los números que son divisibles por 7 en un rango dado de `0` a `n`. ## 💡 Pista: -+ Considera usar `yield`. ++ Lee sobre funciones generadoras y `yield`: https://sentry.io/answers/python-yield-keyword/ From adf728af443bf3ef00093700ef29586c85b531c3 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 04:43:21 +0100 Subject: [PATCH 69/83] Update README.es.md --- exercises/39-class-that-iterates/README.es.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/39-class-that-iterates/README.es.md b/exercises/39-class-that-iterates/README.es.md index a283641d..4cdc477f 100644 --- a/exercises/39-class-that-iterates/README.es.md +++ b/exercises/39-class-that-iterates/README.es.md @@ -2,8 +2,10 @@ ## 📝 Instrucciones: -1. Define una clase con una función generadora que pueda iterar los números que son divisibles por 7 en un rango dado de `0` a `n`. +1. Define una clase con una *generator function* que pueda iterar los números que son divisibles por 7 en un rango dado de `0` a `n`. ## 💡 Pista: -+ Lee sobre funciones generadoras y `yield`: https://sentry.io/answers/python-yield-keyword/ ++ Lee sobre *generator functions* y `yield`: https://sentry.io/answers/python-yield-keyword/ + ++ Debes usar `yield` en tu solución. From 5be39e59da3d0224aa147761b9795ce66189c51f Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 04:43:26 +0100 Subject: [PATCH 70/83] Update README.es.md --- exercises/39-class-that-iterates/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/39-class-that-iterates/README.es.md b/exercises/39-class-that-iterates/README.es.md index 4cdc477f..2de07c5a 100644 --- a/exercises/39-class-that-iterates/README.es.md +++ b/exercises/39-class-that-iterates/README.es.md @@ -4,7 +4,7 @@ 1. Define una clase con una *generator function* que pueda iterar los números que son divisibles por 7 en un rango dado de `0` a `n`. -## 💡 Pista: +## 💡 Pistas: + Lee sobre *generator functions* y `yield`: https://sentry.io/answers/python-yield-keyword/ From 93ecba37a33c5fa92c3db89b83e029b358ce5d54 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 04:52:11 +0100 Subject: [PATCH 71/83] Update README.md --- exercises/39-class-that-iterates/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exercises/39-class-that-iterates/README.md b/exercises/39-class-that-iterates/README.md index ceb6a0f7..795954d5 100644 --- a/exercises/39-class-that-iterates/README.md +++ b/exercises/39-class-that-iterates/README.md @@ -7,3 +7,5 @@ ## 💡 Hint: + Read about generator functions and `yield`: https://sentry.io/answers/python-yield-keyword/ + ++ You must use `yield` on your solution. From 50518dd7a62b563787f53ae0b3a3a1f23bee3752 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 04:52:55 +0100 Subject: [PATCH 72/83] Update README.md --- exercises/39-class-that-iterates/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/39-class-that-iterates/README.md b/exercises/39-class-that-iterates/README.md index 795954d5..0e8fce0a 100644 --- a/exercises/39-class-that-iterates/README.md +++ b/exercises/39-class-that-iterates/README.md @@ -2,7 +2,7 @@ ## 📝 Instructions: -1. Define a class with a generator function that can iterate the numbers that are divisible by 7, between a given range `0` and `n`. +1. Define a class with a generator function that can iterate the numbers that are divisible by 7 between a given range `0` and `n`. ## 💡 Hint: From d978db0c33ee013fce596bff94d9f272655e454d Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 04:53:49 +0100 Subject: [PATCH 73/83] Update README.md --- exercises/39-class-that-iterates/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/39-class-that-iterates/README.md b/exercises/39-class-that-iterates/README.md index 0e8fce0a..0be2186d 100644 --- a/exercises/39-class-that-iterates/README.md +++ b/exercises/39-class-that-iterates/README.md @@ -4,7 +4,7 @@ 1. Define a class with a generator function that can iterate the numbers that are divisible by 7 between a given range `0` and `n`. -## 💡 Hint: +## 💡 Hints: + Read about generator functions and `yield`: https://sentry.io/answers/python-yield-keyword/ From 762b3e981b84a27384abb664a87e79b3f121c221 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 05:15:58 +0100 Subject: [PATCH 74/83] Update README.md --- exercises/40-compute-robot-distance/README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/exercises/40-compute-robot-distance/README.md b/exercises/40-compute-robot-distance/README.md index 4d2340ee..34d669e0 100644 --- a/exercises/40-compute-robot-distance/README.md +++ b/exercises/40-compute-robot-distance/README.md @@ -2,19 +2,18 @@ ## 📝 Instructions: -A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with given steps. The trace of robot movement is shown as the following: +A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with given steps. The trace of robot movement is shown as a list like the following: -+ UP 5 -+ DOWN 3 -+ LEFT 3 -+ RIGHT 2 +```py +["UP 5", "DOWN 3", "LEFT 3", "RIGHT 2"] +``` The numbers after the direction are steps. Please write a program named `compute_robot_distance()` to compute the final distance after a sequence of movements from the original point. If the distance is a float, then just print the nearest integer. ## 📎 Example input: ```py -compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2") +compute_robot_distance(["UP 5", "DOWN 3", "LEFT 3", "RIGHT 2"]) ``` ## 📎 Example output: From 584277f009aa298e5a65f42629d67e7c2784098e Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 05:16:19 +0100 Subject: [PATCH 75/83] Update solution.hide.py --- .../solution.hide.py | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/exercises/40-compute-robot-distance/solution.hide.py b/exercises/40-compute-robot-distance/solution.hide.py index 17af8bcd..439dc0a3 100644 --- a/exercises/40-compute-robot-distance/solution.hide.py +++ b/exercises/40-compute-robot-distance/solution.hide.py @@ -1,20 +1,23 @@ # Your code here -import math +def compute_robot_distance(movements): + x, y = 0, 0 -def compute_robot_distance(props): - pos = [0,0] - new_prop = props.split(" ") - for x in range(len(new_prop)): - if new_prop[x].upper() == 'UP': - pos[0]+=int(new_prop[x+1]) - elif new_prop[x].upper() == 'DOWN': - pos[0]-=int(new_prop[x+1]) - elif new_prop[x].upper() == 'LEFT': - pos[1]-=int(new_prop[x+1]) - elif new_prop[x].upper() == 'RIGHT': - pos[1]+=int(new_prop[x+1]) - else: - None - return (int(round(math.sqrt(pos[1]**2+pos[0]**2)))) + for move in movements: + direction, steps = move.split() + steps = int(steps) -print(compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2")) + if direction == "UP": + y += steps + elif direction == "DOWN": + y -= steps + elif direction == "LEFT": + x -= steps + elif direction == "RIGHT": + x += steps + + distance = (x**2 + y**2)**0.5 + rounded_distance = round(distance) + + return rounded_distance + +print(compute_robot_distance(["UP 5", "DOWN 3", "LEFT 3", "RIGHT 2"])) From 58e5a67bf6b4b70b1118b88eacc05b0f161dccdb Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 05:23:17 +0100 Subject: [PATCH 76/83] Update README.es.md --- exercises/40-compute-robot-distance/README.es.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/exercises/40-compute-robot-distance/README.es.md b/exercises/40-compute-robot-distance/README.es.md index e62a7ac3..11503800 100644 --- a/exercises/40-compute-robot-distance/README.es.md +++ b/exercises/40-compute-robot-distance/README.es.md @@ -2,19 +2,18 @@ ## 📝 Instrucciones: -Un robot se mueve en un plano comenzando desde el punto de inicio (0,0). El robot puede moverse hacia ARRIBA (UP), ABAJO (DOWN), IZQUIERDA (LEFT) y DERECHA (RIGHT) con pasos dados por parámetro. La traza del movimiento del robot se muestra de la siguiente manera: +Un robot se mueve en un plano comenzando desde el punto de inicio (0,0). El robot puede moverse hacia ARRIBA (UP), ABAJO (DOWN), IZQUIERDA (LEFT) y DERECHA (RIGHT) con pasos dados por parámetro. La traza del movimiento del robot se muestra como una lista de la siguiente manera: -+ UP 5 -+ DOWN 3 -+ LEFT 3 -+ RIGHT 2 +```py +["UP 5", "DOWN 3", "LEFT 3", "RIGHT 2"] +``` Los números después de la dirección son los pasos. Por favor, escribe un programa llamado `compute_robot_distance()` para calcular la distancia final después de una secuencia de movimientos desde el punto original. Si la distancia es un número decimal, simplemente imprime el entero más cercano. ## 📎 Ejemplo de entrada: ```py -compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2") +compute_robot_distance(["UP 5", "DOWN 3", "LEFT 3", "RIGHT 2"]) ``` ## 📎 Ejemplo de salida: From bda54487e4158ba72672d3a2106f514a5a57205c Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 05:24:53 +0100 Subject: [PATCH 77/83] Update test.py --- exercises/40-compute-robot-distance/test.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/exercises/40-compute-robot-distance/test.py b/exercises/40-compute-robot-distance/test.py index d976852f..a9175576 100644 --- a/exercises/40-compute-robot-distance/test.py +++ b/exercises/40-compute-robot-distance/test.py @@ -1,18 +1,20 @@ import pytest, io, sys, json, mock, re, os - @pytest.mark.it('The function compute_robot_distance must exist') def test_function_existence(capsys, app): assert app.compute_robot_distance @pytest.mark.it('The function should return the expected output') def test_expected_output(capsys, app): - assert app.compute_robot_distance("UP 5 DOWN 3 LEFT 3 RIGHT 2") == 2 + movements_list = ["UP 5", "DOWN 3", "LEFT 3", "RIGHT 2"] + assert app.compute_robot_distance(movements_list) == 2 @pytest.mark.it('The solution should work with other entries') def test_another_output(capsys, app): - assert app.compute_robot_distance("DOWN 20 UP 5 LEFT 5 RIGHT 2") == 15 + movements_list = ["DOWN 20", "UP 5", "LEFT 5", "RIGHT 2"] + assert app.compute_robot_distance(movements_list) == 15 -@pytest.mark.it('The solution should work with other entries') +@pytest.mark.it('The solution should work with negative inputs') def test_negative_inputs(capsys, app): - assert app.compute_robot_distance("DOWN -1 UP -5 LEFT 50 RIGHT 20") == 30 + movements_list = ["DOWN -1", "UP -5", "LEFT 50", "RIGHT 20"] + assert app.compute_robot_distance(movements_list) == 30 From 255205e2a1bcd32c789e9162b02ca345555b8812 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 06:17:06 +0100 Subject: [PATCH 78/83] Update README.md --- exercises/41-frequency-of-words/README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exercises/41-frequency-of-words/README.md b/exercises/41-frequency-of-words/README.md index 443e8204..ba8490a7 100644 --- a/exercises/41-frequency-of-words/README.md +++ b/exercises/41-frequency-of-words/README.md @@ -2,7 +2,11 @@ ## 📝 Instructions: -1. Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically. +1. Write a function called `compute_word_frequency()` to compute the frequency of the words from a string input. + +2. Put each word separated by a space in a dictionary and count its frequency. + +3. Sort the dictionary alphanumerically and print in the console each key in a new line. ## 📎 Example input: @@ -12,7 +16,7 @@ ## 📎 Example output: -```py +```text 2: 2 3.: 1 3?: 1 @@ -25,3 +29,7 @@ choosing: 1 or: 2 to: 1 ``` + +## 💡 Hint: + ++ You can put each word of a string in a list with the `split()` method, then it is easier to work on it. From 90846cc25a311dfbb3e8ff257de885421b039532 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 06:23:43 +0100 Subject: [PATCH 79/83] Update README.es.md --- exercises/41-frequency-of-words/README.es.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/exercises/41-frequency-of-words/README.es.md b/exercises/41-frequency-of-words/README.es.md index 2bb286c2..89c61e32 100644 --- a/exercises/41-frequency-of-words/README.es.md +++ b/exercises/41-frequency-of-words/README.es.md @@ -2,17 +2,21 @@ ## 📝 Instrucciones: -1. Escribe un programa para calcular la frecuencia de las palabras a partir de la entrada. La salida debe mostrarse después de ordenar las claves alfanuméricamente. +1. Escribe una función llamada `compute_word_frequency()` para calcular la frecuencia de las palabras a partir de un string de entrada. + +2. Coloca cada palabra separada por un espacio en un diccionario y cuenta su frecuencia. + +3. Ordena el diccionario alfanuméricamente e imprime en la consola cada clave en una nueva línea. ## 📎 Ejemplo de entrada: ```py -"New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3." +compute_word_frequency("New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.") ``` ## 📎 Ejemplo de salida: -```py +```text 2: 2 3.: 1 3?: 1 @@ -25,3 +29,7 @@ choosing: 1 or: 2 to: 1 ``` + +## 💡 Pista: + ++ Puedes poner cada palabra de un string en una lista con el método `split()`, luego te será mucho más fácil trabajar en la solución. From 4916ff4bfd5a71eb8476bf886111c45e9b35d64c Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 06:24:01 +0100 Subject: [PATCH 80/83] Update README.md --- exercises/41-frequency-of-words/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/41-frequency-of-words/README.md b/exercises/41-frequency-of-words/README.md index ba8490a7..f13806a1 100644 --- a/exercises/41-frequency-of-words/README.md +++ b/exercises/41-frequency-of-words/README.md @@ -11,7 +11,7 @@ ## 📎 Example input: ```py -"New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3." +compute_word_frequency("New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.") ``` ## 📎 Example output: From 5adb95e72346e558b008a84b2ae780af885b1d30 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Mon, 1 Jan 2024 06:24:36 +0100 Subject: [PATCH 81/83] Update solution.hide.py --- .../41-frequency-of-words/solution.hide.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/exercises/41-frequency-of-words/solution.hide.py b/exercises/41-frequency-of-words/solution.hide.py index 8c9f61fb..a2df503d 100644 --- a/exercises/41-frequency-of-words/solution.hide.py +++ b/exercises/41-frequency-of-words/solution.hide.py @@ -1,10 +1,17 @@ -freq = {} # frequency of words in text -line = input() -for word in line.split(): - freq[word] = freq.get(word,0)+1 +# Your code here +def compute_word_frequency(sentence): + words = sentence.split() -words = freq.keys() -words.sort() + word_frequency = {} -for w in words: - print ("%s:%d" % (w,freq[w])) \ No newline at end of file + for word in words: + word_frequency[word] = word_frequency.get(word, 0) + 1 + + sorted_word_frequency = sorted(word_frequency.items(), key=lambda x: x[0]) + + for word, frequency in sorted_word_frequency: + print(f"{word}: {frequency}") + + +input_sentence = "New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3." +compute_word_frequency(input_sentence) From 5121f6c1e1f6b25ff27c113acfea511ae9cd76d5 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:28:00 +0100 Subject: [PATCH 82/83] Update solution.hide.py --- .../37-validity-of-password/solution.hide.py | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/exercises/37-validity-of-password/solution.hide.py b/exercises/37-validity-of-password/solution.hide.py index dff22c64..cca0ee73 100644 --- a/exercises/37-validity-of-password/solution.hide.py +++ b/exercises/37-validity-of-password/solution.hide.py @@ -2,35 +2,12 @@ import re def valid_password(password): - if len(password) < 6 or len(password) > 12: + pattern = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[$#@]).{6,12}$') + + if pattern.match(password): + return "Valid password" + else: return "Invalid password. Please try again" - if not re.search("[a-z]", password): - return "Invalid password. Please try again" - elif not re.search("[0-9]", password): - return "Invalid password. Please try again" - elif not re.search("[A-Z]", password): - return "Invalid password. Please try again" - elif not re.search("[$#@]", password): - return "Invalid password. Please try again" - elif re.search("\s", password): - return "Invalid password. Please try again" - - return "Valid password" print(valid_password("ABd1234@1")) - - -### SOLUTION 2 ### - -# import re - -# def valid_password(password): -# pattern = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[$#@]).{6,12}$') - -# if pattern.match(password): -# return "Valid password" -# else: -# return "Invalid password. Please try again" - -# print(valid_password("ABd1234@1")) From b95c13dfe61a9223be01cbe755bb1f655d33a58b Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:30:16 +0100 Subject: [PATCH 83/83] Update solution.hide.py --- exercises/37-validity-of-password/solution.hide.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/37-validity-of-password/solution.hide.py b/exercises/37-validity-of-password/solution.hide.py index cca0ee73..e114a09e 100644 --- a/exercises/37-validity-of-password/solution.hide.py +++ b/exercises/37-validity-of-password/solution.hide.py @@ -4,10 +4,10 @@ def valid_password(password): pattern = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[$#@]).{6,12}$') - if pattern.match(password): - return "Valid password" - else: + if not pattern.match(password): return "Invalid password. Please try again" + else: + return "Valid password" print(valid_password("ABd1234@1"))