Skip to content

Commit a9a79d9

Browse files
authored
Merge pull request 4GeeksAcademy#58 from josemoracard/jose7-28-sequence-of-lines
exercises 28-sequence-of-lines to 34-a-aa-aaa-aaaa
2 parents dfbfb9b + 7bc11bf commit a9a79d9

33 files changed

+325
-124
lines changed
+17-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# `28` Sequence of lines
22

3-
Escribe un programa que acepte una secuencia de líneas como entrada y que luego imprima las líneas convirtiendo todos los caracteres en mayúscula.
3+
## 📝 Instrucciones:
44

5-
Supongamos le entregamos la siguiente entrada al programa:
6-
Hello world
7-
Practice makes perfect
8-
El resultado debería ser este:
9-
HELLO WORLD
10-
PRACTICE MAKES PERFECT
5+
1. Escribe la función `lines()`. Dado un string, haz que la función retorne todos los caracteres del string en mayúsculas.
116

12-
Pistas:
13-
En caso de que se le pasen entradas de datos a la pregunta, deben asumirse como entradas de la consola.
7+
## 📎 Ejemplo de entrada:
8+
9+
```py
10+
lines("Hello world, practice makes perfect")
11+
```
12+
13+
## 📎 Ejemplo de salida:
14+
15+
```text
16+
HELLO WORLD, PRACTICE MAKES PERFECT
17+
```
18+
19+
## 💡 Pista:
20+
21+
+ Googlea cómo convertir un string a mayúsculas en Python.
+19-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# `28` Sequence of lines
22

3-
Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.
4-
Suppose the following input is supplied to the program:
5-
Hello world
6-
Practice makes perfect
7-
Then, the output should be:
8-
HELLO WORLD
9-
PRACTICE MAKES PERFECT
10-
11-
Hints:
12-
In case of input data being supplied to the question, it should be assumed to be a console input.
13-
14-
Solution:
3+
## 📝 Instructions:
4+
5+
1. Write a function `lines()`. Given a string, make the function return all the characters from the string capitalized.
6+
7+
## 📎 Example input:
8+
9+
```py
10+
lines("Hello world, practice makes perfect")
11+
```
12+
13+
## 📎 Example output:
14+
15+
```text
16+
HELLO WORLD, PRACTICE MAKES PERFECT
17+
```
18+
19+
## 💡 Hint:
20+
21+
+ Google how to capitalize a string in Python.

exercises/28-sequence-of-lines/app.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Your code here
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
# Your code here
12
def lines(text):
23
return text.upper()
34

4-
print(lines('Hello world'))
5+
print(lines('Hello world, practice makes perfect'))

exercises/28-sequence-of-lines/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ def test_function_existence(capsys, app):
99
def test_expected_output(capsys, app):
1010
assert app.lines("hello world") == "HELLO WORLD"
1111

12-
@pytest.mark.it('The function should return the expected output')
12+
@pytest.mark.it('The function should return the expected output. Testing with a different value')
1313
def test_another_output(capsys, app):
1414
assert app.lines("LeT the WOrld know YoU") == "LET THE WORLD KNOW YOU"
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
# `29`Eliminar los duplicados
1+
# `29` Remove duplicate words
22

3-
Escribe un programa que acepte una secuencia de palabras separadas por espacios en blanco como entrada y que imprima luego las palabras eliminando todas las duplicadas y ordenándolas alfanuméricamente.
3+
## 📝 Instrucciones:
44

5-
Supongamos que se le entrega la siguiente entrada al programa:
5+
1. Escribe la función `remove_duplicate_words()` que tome una secuencia de palabras separadas por espacios en blanco como entrada. Luego, retorna las palabras eliminando duplicados y organizándolas alfanuméricamente.
66

7-
hello world and practice makes perfect and hello world again
7+
## 📎 Ejemplo de entrada:
88

9-
El resultado debería ser:
9+
```py
10+
remove_duplicate_words("hello world and practice makes perfect and hello world again")
11+
```
1012

11-
again and hello makes perfect practice world
13+
## 📎 Ejemplo de salida:
1214

13-
Pistas:
14-
En caso de que se le entregue entradas de datos a la pregunta, debe asumirse como entrada de la consola.
15+
```text
16+
again and hello makes perfect practice world
17+
```
1518

16-
Usa set container para eliminar los datos duplicados automáticamente y luego usa sorted() para ordenar los datos.
19+
## 💡 Pistas:
1720

21+
+ Puedes convertir tu entrada en el tipo de dato `set` para eliminar automáticamente cualquier duplicado.
1822

23+
+ Puedes utilizar `sorted()` para ordenar los elementos de una lista.
+18-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
# `29` Remove duplicate words
22

3-
Write a program that accepts a sequence of whitespace separated words as input and prints the words after removing all duplicate words and sorting them alphanumerically.
4-
Suppose the following input is supplied to the program:
5-
hello world and practice makes perfect and hello world again
6-
Then, the output should be:
3+
## 📝 Instructions:
4+
5+
1. Write a function called `remove_duplicate_words()` that accepts a sequence of whitespace separated words as input and returns the words after removing all duplicate words and sorting them alphanumerically.
6+
7+
## 📎 Example input:
8+
9+
```py
10+
remove_duplicate_words("hello world and practice makes perfect and hello world again")
11+
```
12+
13+
## 📎 Example output:
14+
15+
```text
716
again and hello makes perfect practice world
17+
```
18+
19+
## 💡 Hints:
820

9-
Hints:
10-
In case of input data being supplied to the question, it should be assumed to be a console input.
11-
We use set container to remove duplicated data automatically and then use sorted() to sort the data.
21+
+ You can convert your input into the `set` data type to automatically eliminate duplicates.
1222

23+
+ You can use `sorted()` to sort the data from a list.
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
s = input()
2-
words = [word for word in s.split(" ")]
3-
print (" ".join(sorted(list(set(words)))))
1+
# Your code here
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Your code here
12
def remove_duplicate_words(text):
23
words = text.split()
34
return (" ".join(sorted(list(set(words)))))
5+
6+
print(remove_duplicate_words("hello world and practice makes perfect and hello world again"))

exercises/29-remove-duplicate-words/test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ def test_function_existence(capsys, app):
88
def test_expected_output(capsys, app):
99
assert app.remove_duplicate_words("hello world and practice makes perfect and hello world again") == "again and hello makes perfect practice world"
1010

11-
@pytest.mark.it('The function should work with other entries')
11+
@pytest.mark.it('The function should work with other entries. Testing with different values')
1212
def test_expected_output_2(capsys, app):
1313
assert app.remove_duplicate_words("lets try this again with another try") == "again another lets this try with"
1414

15-
@pytest.mark.it('The function should work with other entries')
15+
@pytest.mark.it('The function should work with other entries. Testing with different values')
1616
def test_expected_output_3(capsys, app):
1717
assert app.remove_duplicate_words("Jacke was Named Jacke by his mother") == "Jacke Named by his mother was"
1818

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# `30` Divisable binary
2+
3+
## 📝 Instrucciones:
4+
5+
1. Escribe la función `divisible_binary()` que tome una secuencia de números binarios de 4 dígitos separados por comas como entrada y verifique si son divisibles por 5. Imprime los números que son divisibles por 5 en una secuencia separada por comas.
6+
7+
## 📎 Ejemplo de entrada:
8+
9+
```py
10+
divisible_binary("0100,0011,1010,1001")
11+
```
12+
13+
## 📎 Ejemplo de salida:
14+
15+
```py
16+
1010
17+
```
18+
19+
## 💡 Pista:
20+
21+
+ Para convertir números binarios en nuestros números enteros cotidianos (base 10 o decimal), es necesario incluir la base del número que ingresamos en el primer argumento (en este caso, base 2 o binario), y la función `int()` se encargará del resto. Sería así:
22+
23+
```py
24+
binary = '0101'
25+
decimal = int(binary, 2)
26+
27+
print(decimal) # Output: 5
28+
```
+26-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1-
Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.
2-
Example:
3-
0100,0011,1010,1001
4-
Then the output should be:
1+
# `30` Divisable binary
2+
3+
## 📝 Instructions:
4+
5+
1. Write a function `divisible_binary()` that takes a sequence of comma-separated 4-digit binary numbers as input and checks if they are divisible by 5. Print the numbers that are divisible by 5 in a comma-separated sequence.
6+
7+
## 📎 Example input:
8+
9+
```py
10+
divisible_binary("0100,0011,1010,1001")
11+
```
12+
13+
## 📎 Example output:
14+
15+
```py
516
1010
6-
Notes: Assume the data is input by console.
17+
```
18+
19+
## 💡 Hint:
20+
21+
+ To convert binary numbers into our everyday integer numbers (base 10 or decimal), you have to include the base of the number we input in the first argument (in this case, base 2 or binary), and the function `int()` will take care of the rest. Like this:
22+
23+
```py
24+
binary = '0101'
25+
decimal = int(binary, 2)
726

8-
Hints:
9-
In case of input data being supplied to the question, it should be assumed to be a console input.
27+
print(decimal) # Output: 5
28+
```

exercises/30-divisable-binary/app.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Your code here
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
def divisable_binary(text):
2-
value=[]
3-
items=[x for x in text.split(',')]
4-
for p in items:
5-
intp = int(p, 2)
6-
if not intp%5:
7-
value.append(p)
1+
# Your code here
2+
def divisible_binary(binary_sequence):
3+
divisible_numbers = []
4+
binary_numbers = [x for x in binary_sequence.split(',')]
5+
for binary_num in binary_numbers:
6+
int_binary_num = int(binary_num, 2)
7+
if not int_binary_num % 5:
8+
divisible_numbers.append(binary_num)
89

9-
return (','.join(value))
10+
return ','.join(divisible_numbers)
11+
12+
print(divisible_binary("1000,1100,1010,1111"))

exercises/30-divisable-binary/test.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import pytest, io, sys, json, mock, re, os
22

3-
@pytest.mark.it('The function divisable_binary must exist')
3+
@pytest.mark.it('The function divisible_binary must exist')
44
def test_function_existence(capsys, app):
5-
assert app.divisable_binary
5+
assert app.divisible_binary
66

77
@pytest.mark.it('The function should return the expected output')
88
def test_expected_output(capsys, app):
9-
assert app.divisable_binary("0100,0011,1010,1001") == "1010"
9+
assert app.divisible_binary("0100,0011,1010,1001") == "1010"
1010

1111
@pytest.mark.it('The function should work with other parameters. testing with 1111,1000,0101,0000')
1212
def test_expected_output_2(capsys, app):
13-
assert app.divisable_binary("1111,1000,0101,0000") == "1111,0101,0000"
13+
assert app.divisible_binary("1111,1000,0101,0000") == "1111,0101,0000"
1414

1515
@pytest.mark.it("The function should work with other parameters. Testing with 1000")
1616
def test_expected_output_3(capsys, app):
17-
assert app.divisable_binary("1000,1000,1000,1000") == ""
17+
assert app.divisible_binary("1000,1000,1000,1000") == ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `31` All digits even
2+
3+
## 📝 Instrucciones:
4+
5+
1. Define una función llamada `all_digits_even()` para identificar e imprimir todos los números entre 1000 y 3000 (inclusive) en los que cada dígito es un número par. Muestra los números resultantes en una secuencia separada por comas en una sola línea.
+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
Write a program, which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.
2-
The numbers obtained should be printed in a comma-separated sequence on a single line.
1+
# `31` All digits even
32

4-
Hints:
5-
In case of input data being supplied to the question, it should be assumed to be a console input.
3+
## 📝 Instructions:
64

7-
Solution:
5+
1. Define a function named `all_digits_even()` to identify and print all numbers between 1000 and 3000 (inclusive) where each digit is an even number. Display the resulting numbers in a comma-separated sequence on a single line.

exercises/31-sum-eigth-digit/app.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Your code here
+11-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
values = []
2-
for i in range(1000, 3001):
3-
s = str(i)
4-
if (int(s[0])%2==0) and (int(s[1])%2==0) and (int(s[2])%2==0) and (int(s[3])%2==0):
5-
values.append(s)
6-
print ",".join(values)
1+
# Your code here
2+
def all_digits_even():
3+
values = []
4+
for i in range(1000, 3001):
5+
s = str(i)
6+
if (int(s[0]) % 2 == 0) and (int(s[1]) % 2 == 0) and (int(s[2]) % 2 == 0) and (int(s[3]) % 2 == 0):
7+
values.append(s)
8+
9+
return ",".join(values)
10+
11+
print(all_digits_even())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# `32` Number of letters and digits
2+
3+
## 📝 Instrucciones:
4+
5+
1. Escribe una función llamada `letters_and_digits()` que tome una oración como entrada y calcule la cantidad de letras y dígitos presentes en ella.
6+
7+
## 📎 Ejemplo de entrada:
8+
9+
```py
10+
letters_and_digits("hello world! 123")
11+
```
12+
13+
## 📎 Ejemplo de salida:
14+
15+
```text
16+
LETTERS 10
17+
DIGITS 3
18+
```
19+
20+
## 💡 Pista:
21+
22+
+ Declara un diccionario para guardar ambas cuentas en una sola variable.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
Write a program that accepts a sentence and calculate the number of letters and digits.
2-
Suppose the following input is supplied to the program:
3-
hello world! 123
4-
Then, the output should be:
1+
# `32` Number of letters and digits
2+
3+
## 📝 Instructions:
4+
5+
1. Write a function named `letters_and_digits()` that takes a sentence as input and calculates the number of letters and digits present in it.
6+
7+
## 📎 Example input:
8+
9+
```py
10+
letters_and_digits("hello world! 123")
11+
```
12+
13+
## 📎 Example output:
14+
15+
```text
516
LETTERS 10
617
DIGITS 3
18+
```
19+
20+
## 💡 Hint:
721

8-
Hints:
9-
In case of input data being supplied to the question, it should be assumed to be a console input.
22+
+ Declare a dictionary for storing both counts in one variable.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Your code here

0 commit comments

Comments
 (0)