Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions exercises/exercise3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Único return vs múltiples return."""

from typing import Union
from unittest import result


def operacion_basica(a: float, b: float, multiplicar: bool) -> Union[float, str]: # noqa: E501
Expand All @@ -17,6 +18,16 @@ def operacion_basica(a: float, b: float, multiplicar: bool) -> Union[float, str]


# NO MODIFICAR - INICIO

if multiplicar:
result = a*b
elif b!=0:
result = a/b
else:
result = "Operación no válida"
return result


assert operacion_basica(1, 1, True) == 1
assert operacion_basica(1, 1, False) == 1
assert operacion_basica(25, 5, True) == 125
Expand All @@ -43,6 +54,13 @@ def operacion_multiple(a: float, b: float, multiplicar: bool) -> Union[float, st


# NO MODIFICAR - INICIO

if not multiplicar:
if b == 0:
return "Operación no válida"
return a/b
return a*b

assert operacion_multiple(1, 1, True) == 1
assert operacion_multiple(1, 1, False) == 1
assert operacion_multiple(25, 5, True) == 125
Expand Down
67 changes: 45 additions & 22 deletions exercises/exercise4.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
"""Expresiones Booleanas."""


def es_vocal_if(letra: str) -> bool:
"""Toma un string y devuelve un booleano en base a si letra es una vocal o
no.
def es_vocal_if(letra: str) -> bool:
"""Toma un string y devuelve un booleano en base a si letra es una vocal o
no.

Restricciónes:
- Utilizar un if para cada posibilidad.
- Utilizar la función lower() sólo una vez.
- No utilizar ELSE.
- Utilizar 6 returns.

Referencia: https://docs.python.org/3/library/stdtypes.html#string-methods
"""


# NO MODIFICAR - INICIO

if letra == "A" or letra == "a":
return True
if letra == "E" or letra == "e":
return True
if letra == "I" or letra.lower() == "i":
return True
if letra == "O" or letra == "o":
return True
if letra == "U" or letra == "u":
return True
return False

assert es_vocal_if("a")
assert not es_vocal_if("b")
assert es_vocal_if("A")
assert es_vocal_if("e")
assert es_vocal_if("E")

Restricciónes:
- Utilizar un if para cada posibilidad.
- Utilizar la función lower() sólo una vez.
- No utilizar ELSE.
- Utilizar 6 returns.

Referencia: https://docs.python.org/3/library/stdtypes.html#string-methods
"""


# NO MODIFICAR - INICIO
assert es_vocal_if("a")
assert not es_vocal_if("b")
assert es_vocal_if("A")
assert es_vocal_if("e")
assert es_vocal_if("E")
# NO MODIFICAR - FIN


Expand All @@ -42,9 +56,15 @@ def es_vocal_if_in(letra: str) -> bool:


# NO MODIFICAR - INICIO
assert es_vocal_if_in("a")
assert not es_vocal_if_in("b")
assert es_vocal_if_in("A")
letra= letra.lower()
if letra in "aeiou":
return True
return False

assert es_vocal_if_in("a")
assert not es_vocal_if_in("b")
assert es_vocal_if_in("A")

# NO MODIFICAR - FIN


Expand All @@ -63,6 +83,9 @@ def es_vocal_in(letra: str) -> bool:


# NO MODIFICAR - INICIO
letra = letra.lower()
return letra in "aeiou"

assert es_vocal_in("a")
assert not es_vocal_in("b")
assert es_vocal_in("A")
Expand Down
18 changes: 18 additions & 0 deletions exercises/exercise5.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ def sumatoria_basico(n: int) -> int:


# NO MODIFICAR - INICIO
suma=0
for i in range(n+1):
suma=suma+i
return suma


assert sumatoria_basico(1) == 1
assert sumatoria_basico(100) == 5050
# NO MODIFICAR - FIN
Expand All @@ -26,6 +32,10 @@ def sumatoria_sum(n: int) -> int:


# NO MODIFICAR - INICIO

retorno=sum(range(n+1), start=0)
return retorno

assert sumatoria_sum(1) == 1
assert sumatoria_sum(100) == 5050
# NO MODIFICAR - FIN
Expand All @@ -50,6 +60,14 @@ def multiplicar_basico(numeros: Iterable[float]) -> float:


# NO MODIFICAR - INICIO

resultado=1
if len(numeros)==0:
return 0
for i in numeros:
resultado=resultado*i
return resultado

assert multiplicar_basico([1, 2, 3, 4]) == 24
assert multiplicar_basico([2, 5]) == 10
assert multiplicar_basico([]) == 0
Expand Down
21 changes: 21 additions & 0 deletions exercises/exercise6.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ def numeros_al_final_basico(lista: List[Union[float, str]]) -> List[Union[float,


# NO MODIFICAR - INICIO

cadenas=[]
numeros=[]
for i in lista:
if type(i) is int:
numeros.append(i)
else:
cadenas.append(i)
cadenas.extend(numeros)
return cadenas



assert numeros_al_final_basico([3, "a", 1, "b", 10, "j"]) == ["a", "b", "j", 3, 1, 10] # noqa: E501
# NO MODIFICAR - FIN

Expand All @@ -32,5 +45,13 @@ def numeros_al_final_comprension(lista: List[Union[float, str]]) -> List[Union[f


# NO MODIFICAR - INICIO

lista_str=[]
lista_int=[]
lista_str=[elemento for elemento in lista if type(elemento) is str]
lista_int=[elemento for elemento in lista if type(elemento) is int]
lista_str.extend(lista_int)
return lista_str

assert numeros_al_final_comprension([3, "a", 1, "b", 10, "j"]) == ["a", "b", "j", 3, 1, 10] # noqa: E501
# NO MODIFICAR - FIN
16 changes: 14 additions & 2 deletions exercises/exercise7.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def superposicion_basico(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool


# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]

for elemento in lista_1:
for elemento2 in lista_2:
if elemento == elemento2:
return True
return False

assert superposicion_basico(test_list, (2, "world", 35.20))
assert not superposicion_basico(test_list, (2, "world", 30.85))
# NO MODIFICAR - FIN
Expand All @@ -33,7 +39,13 @@ def superposicion_in(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool:


# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]

for elemento in lista_1:
if elemento in lista_2:
return True
return False

test_list = [1, "hello", 35.20]
assert superposicion_in(test_list, (2, "world", 35.20))
assert not superposicion_in(test_list, (2, "world", 30.85))
# NO MODIFICAR - FIN
Expand Down
17 changes: 17 additions & 0 deletions exercises/exercise8.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def combinar_basico(nombres: List[str], precios: List[float]) -> Tuple[Any]:


# NO MODIFICAR - INICIO

resultado=[]
for i in range(len(nombres)):
resultado.append((nombres[i],precios[i]))
res=tuple(resultado)
return res

respuesta = (
("ventana", 100.48),
("lámpara", 16.42),
Expand Down Expand Up @@ -54,6 +61,16 @@ def combinar_enumerate(nombres: List[str], precios: List[float], ids: List[int])


# NO MODIFICAR - INICIO

resultado=[]
var=0
for i in enumerate(precios,0):
resultado.append((nombres[var],precios[var],id_articulos[var]))
var=var+1

res=tuple(resultado)
return res

respuesta = (
("ventana", 100.48, 6852),
("lámpara", 16.42, 1459),
Expand Down
10 changes: 10 additions & 0 deletions exercises/exercise9.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def suma_cubo_pares_for(numeros: Iterable[int]) -> int:


# NO MODIFICAR - INICIO
num=[i for i in numeros if i % 2 == 0 ]
resultado=[i**3 for i in num ]
resultado=sum(resultado)
return resultado
assert suma_cubo_pares_for([1, 2, 3, 4, 5, 6]) == 288
# NO MODIFICAR - FIN

Expand All @@ -36,6 +40,9 @@ def suma_cubo_pares_sum_list(numeros: Iterable[int]) -> int:


# NO MODIFICAR - INICIO
resultado = [x**3 for x in numeros if x%2==0]
resultado=sum(resultado)
return resultado
assert suma_cubo_pares_sum_list([1, 2, 3, 4, 5, 6]) == 288
# NO MODIFICAR - FIN

Expand Down Expand Up @@ -75,6 +82,9 @@ def suma_cubo_pares_sum_list(numeros: Iterable[int]) -> int:


# NO MODIFICAR - INICIO
numeros_al_cubo = list(map(lambda x : x ** 3, numeros))
numeros_al_cubo_pares = list(filter(lambda x : x % 2 == 0, numeros_al_cubo))
suma_numeros_al_cubo_pares = reduce(lambda x, y: x + y, numeros_al_cubo_pares)
assert numeros_al_cubo == [1, 8, 27, 64, 125, 216]
assert numeros_al_cubo_pares == [8, 64, 216]
assert suma_numeros_al_cubo_pares == 288
Expand Down