Skip to content

exercises 35-square-each-odd-number to 41-frequency-of-words #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
ec5641c
Update solution.hide.py
josemoracard Dec 20, 2023
f7534ae
Update app.py
josemoracard Dec 20, 2023
ad17111
Update README.md
josemoracard Dec 20, 2023
58cb51c
Create README.es.md
josemoracard Dec 20, 2023
ec7c404
Update solution.hide.py
josemoracard Dec 20, 2023
bbb3734
Update app.py
josemoracard Dec 20, 2023
9a63297
Update test.py
josemoracard Dec 20, 2023
d3d8066
Update README.md
josemoracard Dec 20, 2023
aa9dc78
Create README.es.md
josemoracard Dec 20, 2023
e826bd8
Update README.es.md
josemoracard Dec 20, 2023
d0500b6
Update README.md
josemoracard Dec 20, 2023
72c4780
Update README.md
josemoracard Dec 20, 2023
252579f
Update README.md
josemoracard Dec 20, 2023
285882d
Update app.py
josemoracard Dec 20, 2023
bd82221
Update app.py
josemoracard Dec 20, 2023
95337e9
Create README.es.md
josemoracard Dec 20, 2023
ee3f111
Update README.md
josemoracard Dec 20, 2023
9fb2773
Update README.es.md
josemoracard Dec 20, 2023
dc8d00f
Update README.md
josemoracard Dec 20, 2023
0b91997
Update README.md
josemoracard Dec 20, 2023
236281d
Update README.es.md
josemoracard Dec 20, 2023
459bc2f
Update solution.hide.py
josemoracard Dec 20, 2023
71cdd54
Update solution.hide.py
josemoracard Dec 20, 2023
1860b79
Update README.md
josemoracard Dec 20, 2023
d40a9ad
Update solution.hide.py
josemoracard Dec 20, 2023
dd74f20
Update solution.hide.py
josemoracard Dec 20, 2023
34f92c0
Update app.py
josemoracard Dec 20, 2023
3fb7420
Update app.py
josemoracard Dec 20, 2023
e02e57e
Update README.md
josemoracard Dec 20, 2023
fce6fca
Update README.md
josemoracard Dec 20, 2023
ce2a099
Update README.es.md
josemoracard Dec 20, 2023
66028ab
Update README.md
josemoracard Dec 20, 2023
fbef855
Update README.es.md
josemoracard Dec 20, 2023
d82e4bb
Update test.py
josemoracard Dec 20, 2023
27ce1a1
Update README.es.md
josemoracard Dec 20, 2023
3fd9bd8
Update README.md
josemoracard Dec 20, 2023
8563d94
Update app.py
josemoracard Dec 20, 2023
09ecb60
Create README.es.md
josemoracard Dec 20, 2023
e5de870
Update README.md
josemoracard Dec 20, 2023
ec05b78
Update README.es.md
josemoracard Dec 20, 2023
9a71498
Update README.md
josemoracard Dec 20, 2023
543a5ab
Update app.py
josemoracard Dec 20, 2023
07ec6c3
Update solution.hide.py
josemoracard Dec 20, 2023
e45ddb9
Update README.md
josemoracard Dec 20, 2023
27c687e
Create README.es.md
josemoracard Dec 20, 2023
536cded
Update README.md
josemoracard Dec 20, 2023
1fff9c7
Update test.py
josemoracard Dec 20, 2023
2637b79
Update README.md
josemoracard Dec 20, 2023
087d9ba
Update app.py
josemoracard Dec 20, 2023
c7bb7ad
Create README.es.md
josemoracard Dec 20, 2023
155e5c6
Update README.md
josemoracard Dec 20, 2023
926d7f8
Update README.es.md
josemoracard Dec 20, 2023
042bc62
Update solution.hide.py
josemoracard Jan 1, 2024
64236e9
Update README.es.md
josemoracard Jan 1, 2024
436732c
Update README.es.md
josemoracard Jan 1, 2024
2c2e41d
Update README.md
josemoracard Jan 1, 2024
48b138f
Update README.md
josemoracard Jan 1, 2024
962eff4
Update README.md
josemoracard Jan 1, 2024
041dc4b
Update solution.hide.py
josemoracard Jan 1, 2024
c6a52ad
Update test.py
josemoracard Jan 1, 2024
e8c667b
Update README.md
josemoracard Jan 1, 2024
3244157
Update test.py
josemoracard Jan 1, 2024
c442c87
Update solution.hide.py
josemoracard Jan 1, 2024
8677488
Update README.es.md
josemoracard Jan 1, 2024
ebb3428
Update README.md
josemoracard Jan 1, 2024
bf6d3b6
Update solution.hide.py
josemoracard Jan 1, 2024
2ddeba9
Update README.md
josemoracard Jan 1, 2024
142bbf9
Update README.es.md
josemoracard Jan 1, 2024
adf728a
Update README.es.md
josemoracard Jan 1, 2024
5be39e5
Update README.es.md
josemoracard Jan 1, 2024
93ecba3
Update README.md
josemoracard Jan 1, 2024
50518dd
Update README.md
josemoracard Jan 1, 2024
d978db0
Update README.md
josemoracard Jan 1, 2024
762b3e9
Update README.md
josemoracard Jan 1, 2024
584277f
Update solution.hide.py
josemoracard Jan 1, 2024
58e5a67
Update README.es.md
josemoracard Jan 1, 2024
bda5448
Update test.py
josemoracard Jan 1, 2024
255205e
Update README.md
josemoracard Jan 1, 2024
90846cc
Update README.es.md
josemoracard Jan 1, 2024
4916ff4
Update README.md
josemoracard Jan 1, 2024
5adb95e
Update solution.hide.py
josemoracard Jan 1, 2024
5121f6c
Update solution.hide.py
josemoracard Jan 17, 2024
b95c13d
Update solution.hide.py
josemoracard Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions exercises/35-square-each-odd-number/README.es.md
Original file line number Diff line number Diff line change
@@ -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]
```
25 changes: 17 additions & 8 deletions exercises/35-square-each-odd-number/README.md
Original file line number Diff line number Diff line change
@@ -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.
# `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]
```
1 change: 1 addition & 0 deletions exercises/35-square-each-odd-number/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Your code here
29 changes: 26 additions & 3 deletions exercises/35-square-each-odd-number/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
values = raw_input()
numbers = [x for x in values.split(",") if int(x)%2!=0]
print ",".join(numbers)
# Your code here
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"))
22 changes: 22 additions & 0 deletions exercises/36-net-amount/README.es.md
Original file line number Diff line number Diff line change
@@ -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 por parámetro. 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
```
35 changes: 21 additions & 14 deletions exercises/36-net-amount/README.md
Original file line number Diff line number Diff line change
@@ -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 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.
## 📎 Example input:

```py
net_amount("D 300 D 300 W 200 D 100")
```

## 📎 Example output:

```py
500
```
1 change: 1 addition & 0 deletions exercises/36-net-amount/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Your code here
11 changes: 7 additions & 4 deletions exercises/36-net-amount/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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"))
6 changes: 1 addition & 5 deletions exercises/36-net-amount/test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
assert app.net_amount("W 300 D 300 W 200 W 300") == -500
34 changes: 34 additions & 0 deletions exercises/37-validity-of-password/README.es.md
Original file line number Diff line number Diff line change
@@ -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 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")
```

## 📎 Ejemplo de salida:

```py
"Valid password"
```

## 💡 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`.
42 changes: 24 additions & 18 deletions exercises/37-validity-of-password/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
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 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].
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 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 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 input:

### Example
```py
valid_password("ABd1234@1")
```

If the following passwords are given as input to the program:
## 📎 Example output:

```py
"Valid password"
```
ABd1234@1,a F1#,2w3E*,2We3345
```
Then, the output of the program should be:
```
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 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`.
1 change: 1 addition & 0 deletions exercises/37-validity-of-password/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Your code here
32 changes: 11 additions & 21 deletions exercises/37-validity-of-password/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
# Your code here
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))
pattern = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[$#@]).{6,12}$')

if not pattern.match(password):
return "Invalid password. Please try again"
else:
return "Valid password"


print(valid_password("ABd1234@1"))
6 changes: 3 additions & 3 deletions exercises/37-validity-of-password/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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") == ""
assert app.valid_password("ABd12") == "Invalid password. Please try again"
29 changes: 28 additions & 1 deletion exercises/38-sort-tuples-ascending/README.es.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# `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 `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')]
```

## 💡 Pistas:

+ Utilizamos `itemgetter` para habilitar múltiples claves de orden.

+ Observa que la salida es una lista con tuplas en su interior.
42 changes: 24 additions & 18 deletions exercises/38-sort-tuples-ascending/README.md
Original file line number Diff line number Diff line change
@@ -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`, `age` and `score` are all strings. 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.

The priority is `name` > `age` > `score`.

## 📎 Example input:

```py
sort_tuples_ascending(['Tom,19,80', 'John,20,90', 'Jony,17,91', 'Jony,17,93', 'Jason,21,85'])
```

## 📎 Example output:

```py
[('Jason', '21', '85'), ('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Tom', '19', '80')]
```

## 💡 Hints:

+ We use `itemgetter` to enable multiple sort keys.

+ Notice that the output is a list with tuples inside.
Loading