Skip to content

exercises 24-class-with-two-methods to 27-sequence-of-words #56

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
49 commits
Select commit Hold shift + click to select a range
7293f5d
Update README.md
josemoracard Dec 13, 2023
b8bd2ab
Update README.md
josemoracard Dec 13, 2023
4e885bd
Update README.md
josemoracard Dec 13, 2023
91f258e
Update README.es.md
josemoracard Dec 13, 2023
2ef8e08
Update README.es.md
josemoracard Dec 13, 2023
705c6e9
Update app.py
josemoracard Dec 13, 2023
6c35a1a
Update README.md
josemoracard Dec 13, 2023
ab9322d
Update README.es.md
josemoracard Dec 13, 2023
8aa439a
Update solution.hide.py
josemoracard Dec 13, 2023
48c1c3a
Update README.md
josemoracard Dec 13, 2023
64dfa03
Update README.es.md
josemoracard Dec 13, 2023
7ca65bf
Update solution.hide.py
josemoracard Dec 13, 2023
0d98b29
Update README.md
josemoracard Dec 13, 2023
ca5794f
Update README.md
josemoracard Dec 13, 2023
5019629
Update README.md
josemoracard Dec 13, 2023
7b8812c
Update solution.hide.py
josemoracard Dec 13, 2023
2e6c15f
Update README.md
josemoracard Dec 13, 2023
46581d6
Update solution.hide.py
josemoracard Dec 13, 2023
299a50f
Update test.py
josemoracard Dec 13, 2023
9a77a1b
Update solution.hide.py
josemoracard Dec 13, 2023
28da999
Update app.py
josemoracard Dec 13, 2023
4dec33c
Update README.es.md
josemoracard Dec 13, 2023
509a1ac
Update README.es.md
josemoracard Dec 13, 2023
807e5eb
Update README.md
josemoracard Dec 13, 2023
e31f654
Update README.md
josemoracard Dec 13, 2023
179e4b8
Update README.md
josemoracard Dec 13, 2023
abb91f5
Update README.es.md
josemoracard Dec 13, 2023
f5fc628
Update README.md
josemoracard Dec 13, 2023
0592b58
Update README.es.md
josemoracard Dec 13, 2023
e9846b7
Update app.py
josemoracard Dec 13, 2023
b306c28
Update test.py
josemoracard Dec 13, 2023
dc76fbd
Update solution.hide.py
josemoracard Dec 13, 2023
9d3fd14
Update README.md
josemoracard Dec 13, 2023
93f9ab7
Update README.md
josemoracard Dec 13, 2023
5c3159b
Update README.es.md
josemoracard Dec 13, 2023
829f396
Update test.py
josemoracard Dec 13, 2023
de16793
Update README.md
josemoracard Dec 13, 2023
cf7c26f
Update README.md
josemoracard Dec 13, 2023
9154e2f
Update app.py
josemoracard Dec 13, 2023
e84c78a
Update test.py
josemoracard Dec 13, 2023
d2357f4
Update README.md
josemoracard Dec 13, 2023
9749fe9
Update README.md
josemoracard Dec 13, 2023
f2ba636
Update README.md
josemoracard Dec 13, 2023
94413bf
Update README.es.md
josemoracard Dec 13, 2023
ca9b35b
Update README.md
josemoracard Dec 13, 2023
152aaf9
Update README.md
josemoracard Dec 13, 2023
eb9ff26
Update solution.hide.py
josemoracard Dec 13, 2023
18165ec
Update README.es.md
josemoracard Dec 13, 2023
24ee78f
Update solution.hide.py
josemoracard Dec 13, 2023
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
19 changes: 11 additions & 8 deletions exercises/24-class-with-two-methods/README.es.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# `24` Una clase con dos métodos
# `24` Class with two methods

Define una clase que tenga al menos dos métodos:
Define a class which has at least two methods:
getString: obtener un string desde la entrada de la consola.
printString: imprimir el string en mayúscula.
Por favor incluye una función simple de prueba para probar los métodos de la clase.
## 📝 Instrucciones:

Pistas:
Usa el método __init__ para construir algunos parámetros.
1. Define una clase llamada `InputOutString` que tenga al menos dos métodos:
+ `get_string` para obtener un string de entrada desde la consola.
+ `print_string` para imprimir el string obtenido en mayúsculas.

2. Prueba los métodos de tu clase.

## 💡 Pista:

+ Usa el método `__init__` para construir tus parámetros.
16 changes: 10 additions & 6 deletions exercises/24-class-with-two-methods/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# `24` Class with two methods

Define a class which has at least two methods:
getString: to get a string from console input
printString: to print the string in upper case.
Also please include simple test function to test the class methods.
## 📝 Instructions:

Hints:
Use __init__ method to construct some parameters
1. Define a class called `InputOutString` which has at least two methods:
+ `get_string` to get a string from console input.
+ `print_string` to print the string in upper case.

2. Test your class' methods.

## 💡 Hint:

+ Use the `__init__` method to construct your parameters.
1 change: 1 addition & 0 deletions exercises/24-class-with-two-methods/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Your code here
19 changes: 10 additions & 9 deletions exercises/24-class-with-two-methods/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
class InputOutString(object):
# Your code here
class InputOutString:
def __init__(self):
self.s = ""
self.input_string = ""

def getString(self):
self.s = raw_input()
def get_string(self):
self.input_string = input("Enter a string: ")

def printString(self):
print self.s.upper()
def print_string(self):
print(self.input_string.upper())

strObj = InputOutString()
strObj.getString()
strObj.printString()
string_object = InputOutString()
string_object.get_string()
string_object.print_string()
44 changes: 29 additions & 15 deletions exercises/25-print-formula/README.es.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
# `25` Imprime la fórmula
# `25` Print formula

Escribe un programa que calcule e imprima el valor de acuerdo a la fórmula dada:
## 📝 Instrucciones:

Q = Square root of [(2 * C * D)/H]
1. Escribe una función llamada `print_formula()`, con un parámetro que calcule e imprima el valor según la fórmula dada.

A continuación encontrarás los valores fijos de C y H:
C es 50. H es 30.
D es la variable cuyos valores debiesen ser ingresados en tu
Ejemplo:
Digamos que le sentrega la siguiente secuencia separada por coma al programa:
100,150,180
El resultado del programa debiese ser:
18,22,24
```text
Q = Square root of (2 * c * d) / h
```

Pistas:
Si el resultado recicido es un decimal, debería rendondearse a su valor más cercano (por ejemplo, si el resultado es 26.0, debiese imprimirse como 26)
En el caso de que se le hayan entregado datos a la cuestión, deben asumirse como una entrada de la consola.

*A continuación encontrarás los valores fijos de `c` y `h`:*

+ `c` es 50.
+ `h` es 30.
+ `d` sería el parámetro de la función.

## 📎 Ejemplo de entrada:

```py
print_formula(150)
```

## 📎 Ejemplo de salida:

```py
22
```

## 💡 Pistas:

+ Si el resultado recibido es un decimal, debería redondearse a su valor más cercano (por ejemplo, si el resultado es 26.0, debiese imprimirse como 26).

+ Importa el módulo `math`.
46 changes: 31 additions & 15 deletions exercises/25-print-formula/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
# `25` Print formula

Write a program that calculates and prints the value according to the given formula:
Q = Square root of [(2 * C * D)/H]

Following are the fixed values of C and H:
C is 50. H is 30.
D is the variable whose values should be input to your program in a comma-separated sequence.
Example
Let us assume the following comma separated input sequence is given to the program:
100,150,180
The output of the program should be:
18,22,24

Hints:
If the output received is in decimal form, it should be rounded off to its nearest value (for example, if the output received is 26.0, it should be printed as 26)
In case of input data being supplied to the question, it should be assumed to be a console input.
## 📝 Instructions:

1. Write a function `print_formula()`, with one parameter that calculates and prints the value according to the given formula:

```text
Q = Square root of (2 * c * d) / h
```

*Following are the fixed values of `c` and `h`:*

+ `c` is 50.
+ `h` is 30.
+ `d` would be the parameter of the function.

## 📎 Example input:

```py
print_formula(150)
```

## 📎 Example output:

```py
22
```

## 💡 Hints:

+ If the output received is in decimal form, it should be rounded off to its nearest value (for example, if the output received is 26.0, it should be printed as 26).

+ Import the `math` module.
1 change: 1 addition & 0 deletions exercises/25-print-formula/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Your code here
8 changes: 5 additions & 3 deletions exercises/25-print-formula/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Your code here
import math
def print_formula(num):
return round(math.sqrt(2*50*num/30))

print(print_formula(5))
def print_formula(d):
return round(math.sqrt(2 * 50 * d / 30))

print(print_formula(150))
8 changes: 4 additions & 4 deletions exercises/25-print-formula/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
def test_function_existence(capsys, app):
assert app.print_formula

@pytest.mark.it('The solution should work as expected')
@pytest.mark.it('The solution should work as expected. Testing with 100')
def test_expected_output(capsys, app):
assert app.print_formula(100,150,180) == "18,22,24"
assert app.print_formula(100) == 18

@pytest.mark.it('The solution should work as expected')
@pytest.mark.it('The solution should work as expected. Testing with 90')
def test_another_output(capsys, app):
assert app.print_formula(200,90,300) == "26,17,32"
assert app.print_formula(90) == 17

26 changes: 16 additions & 10 deletions exercises/26-two-dimensional-array/README.es.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# `26` Array de dos dimensiones
# `26` Two dimensional list

Escribe un progrsms que reciba dos dígitos X,Y como entrada y genere un array de dos dimensiones. El valor del elemento en la fila i-th y en la columna j-th del array debiese ser i*j.
Nota: i=0,1.., X-1; j=0,1,¡­Y-1.
Ejemplo:
Supongamos que se le entregan lasa siguientes entradas al programa:
3,5
Entonces, el resultado del programa debería ser:
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
## 📝 Instrucciones:

Pistas:
Nota: En el caso de que se le entreguen datos a la cuestión, debe asumirse como una entrada de la consola en un formulario separado por comas.
1. Escribe una función llamada `two_dimensional_list()` que tome 2 dígitos (x, y) como entrada y genere una lista bidimensional o matriz.

2. El valor del elemento en la fila `i` y columna `j` de la lista debería ser `i*j` (los valores de sus índices).

## 📎 Ejemplo de entrada:

```py
two_dimensional_list(3,5)
```

## 📎 Ejemplo de salida:

```py
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
```
32 changes: 20 additions & 12 deletions exercises/26-two-dimensional-array/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# `26`Two dimensional array

Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.
Note: i=0,1.., X-1; j=0,1,¡­Y-1.
Example
Suppose the following inputs are given to the program:
3,5
Then, the output of the program should be:
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]

Hints:
Note: In case of input data being supplied to the question, it should be assumed to be a console input in a comma-separated form.
# `26` Two dimensional list

## 📝 Instructions:

1. Write a function `two_dimensional_list()`, that takes 2 digits (x, y) as input and generates a 2-dimensional list or matrix.

2. The element value in the `i` row and `j` column of the list should be `i*j` (their index values).

## 📎 Example input:

```py
two_dimensional_list(3,5)
```

## 📎 Example output:

```py
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
```

1 change: 1 addition & 0 deletions exercises/26-two-dimensional-array/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Your code here
21 changes: 12 additions & 9 deletions exercises/26-two-dimensional-array/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
def two_dimensional_array(nList, nElements):
dimensions=[int(x) for x in "{},{}".format(nList,nElements).split(',')]
rowNum=dimensions[0]
colNum=dimensions[1]
multilist = [[0 for col in range(colNum)] for row in range(rowNum)]
# Your code here
def two_dimensional_list(n_rows, n_columns):
dimensions = [int(x) for x in "{},{}".format(n_rows, n_columns).split(',')]
row_num = dimensions[0]
col_num = dimensions[1]
matrix = [[0 for col in range(col_num)] for row in range(row_num)]

for row in range(rowNum):
for col in range(colNum):
multilist[row][col]= row*col
for row in range(row_num):
for col in range(col_num):
matrix[row][col] = row * col

return (multilist)
return matrix

print(two_dimensional_list(3,5))
17 changes: 8 additions & 9 deletions exercises/26-two-dimensional-array/test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@

import pytest,os,re,io,sys, mock, json

@pytest.mark.it('The function two_dimensional_array must exist')
@pytest.mark.it('The function two_dimensional_list must exist')
def test_function_existence(capsys, app):
assert app.two_dimensional_array
assert app.two_dimensional_list

@pytest.mark.it('The function should return the expected output.')
@pytest.mark.it('The function should return the expected output')
def test_expected_output(capsys, app):
assert app.two_dimensional_array(3,5) == [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
assert app.two_dimensional_list(3,5) == [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]

@pytest.mark.it('The function should work with other entries. Testing with 2,7')
@pytest.mark.it('The function should work with other entries. Testing with (2, 7)')
def test_expected_output(capsys, app):
assert app.two_dimensional_array(2,7) == [[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6]]
assert app.two_dimensional_list(2,7) == [[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6]]

@pytest.mark.it('The function should work with other entries. Testing with 2,7')
@pytest.mark.it('The function should work with other entries. Testing with (1, 10)')
def test_expected_output(capsys, app):
assert app.two_dimensional_array(1,10) == [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
assert app.two_dimensional_list(1,10) == [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
29 changes: 21 additions & 8 deletions exercises/27-sequence-of-words/README.es.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# `27` Secuencia de palabras
# `27` Sequence of words

Escribe un programa que acepte una secuencia separada por comas como entrada e imprima las palabras en una secuencia separada por comas después de ordenarlas alfabéticamente.
Supongamos que se le entrega la siguiente entrada al programa:
without,hello,bag,world
El resultado debiese ser:
bag,hello,without,world
## 📝 Instrucciones:

Pistas:
En el caso de que se le entreguen datos a la pregunta, deben considerarse como entradas de la consola.
1. Escribe una función llamada `sequence_of_words()`, que acepte una secuencia de palabras separadas por comas como entrada (un string).

2. Imprime las palabras en una secuencia separada por comas después de ordenarlas alfabéticamente.

## 📎 Ejemplo de entrada:

```py
sequence_of_words("without,hello,bag,world")
```

## 📎 Ejemplo de salida:

```py
bag, hello, without, world
```

## 💡 Pista:

+ Recuerda que cada palabra debe estar separada por una coma y dentro de UN SOLO par de comillas.
29 changes: 21 additions & 8 deletions exercises/27-sequence-of-words/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# `27`Sequence of words
# `27` Sequence of words

Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.
Suppose the following input is supplied to the program:
without,hello,bag,world
Then, the output should be:
bag,hello,without,world
## 📝 Instructions:

Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.
1. Write a function `sequence_of_words`, that accepts a comma separated sequence of words as input (a string).

2. Print the words in a comma-separated sequence after sorting them alphabetically.

## 📎 Example input:

```py
sequence_of_words("without,hello,bag,world")
```

## 📎 Example output:

```py
bag, hello, without, world
```

## 💡 Hint:

+ Remember that each word must be separated by a comma and inside ONLY ONE pair of quotes.
1 change: 1 addition & 0 deletions exercises/27-sequence-of-words/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Your code here
3 changes: 3 additions & 0 deletions exercises/27-sequence-of-words/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Your code here
def sequence_of_words(words):
items=[x for x in "{}".format(words).split(',')]
items.sort()
return (','.join(items))

print(sequence_of_words("this,is,sorted"))
Loading