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
8 changes: 6 additions & 2 deletions exercises/exercise1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def maximo_basico(a: float, b: float) -> float:
- No utilizar ELSE
- No utilizar la función max
"""

if a>b:
return a
elif b>a:
return b

# NO MODIFICAR - INICIO
assert maximo_basico(10, 5) == 10
Expand All @@ -24,6 +27,7 @@ def maximo_libreria(a: float, b: float) -> float:
"""Re-escribir utilizando el built-in max.
Referencia: https://docs.python.org/3/library/functions.html#max
"""
return max(a,b)


# NO MODIFICAR - INICIO
Expand All @@ -39,7 +43,7 @@ def maximo_ternario(a: float, b: float) -> float:
"""Re-escribir utilizando el operador ternario.
Referencia: https://docs.python.org/3/reference/expressions.html#conditional-expressions # noqa: E501
"""

return a if a>b else b

# NO MODIFICAR - INICIO
assert maximo_ternario(10, 5) == 10
Expand Down
10 changes: 7 additions & 3 deletions exercises/exercise2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def maximo_encadenado(a: float, b: float, c: float) -> float:

Referencia: https://docs.python.org/3/reference/expressions.html#comparisons # noqa: E501
"""

if a<b>c:
return b
if b<a>c:
return a
return c

# NO MODIFICAR - INICIO
assert maximo_encadenado(1, 10, 5) == 10
Expand All @@ -37,7 +41,7 @@ def maximo_cuadruple(a: float, b: float, c: float, d: float) -> float:
"""Re-escribir para que tome 4 parámetros, utilizar la función max.

Referencia: https://docs.python.org/3/library/functions.html#max"""

return max(a,b,c,d)

# NO MODIFICAR - INICIO
assert maximo_cuadruple(1, 10, 5, -5) == 10
Expand All @@ -54,7 +58,7 @@ def maximo_arbitrario(*args) -> float:
"""Re-escribir para que tome una cantidad arbitraria de parámetros.
Referencia: https://docs.python.org/3/tutorial/controlflow.html#arbitrary-argument-lists # noqa: E501
"""

return max(args)

# NO MODIFICAR - INICIO
assert maximo_arbitrario(1, 10, 5, -5) == 10
Expand Down
16 changes: 13 additions & 3 deletions exercises/exercise3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Único return vs múltiples return."""

from operator import truediv
from typing import Union


Expand All @@ -14,7 +15,13 @@ def operacion_basica(a: float, b: float, multiplicar: bool) -> Union[float, str]
- Utilizar IF con ELIF con ELSE.
- No utilizar AND ni OR.
"""

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

# NO MODIFICAR - INICIO
assert operacion_basica(1, 1, True) == 1
Expand All @@ -40,8 +47,11 @@ def operacion_multiple(a: float, b: float, multiplicar: bool) -> Union[float, st
- No utilizar ELIF ni ELSE.
- No utilizar AND ni OR.
"""


if multiplicar==True:
return a*b
if b==0:
return "Operación no válida"
return a/b
# NO MODIFICAR - INICIO
assert operacion_multiple(1, 1, True) == 1
assert operacion_multiple(1, 1, False) == 1
Expand Down
28 changes: 24 additions & 4 deletions exercises/exercise4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Expresiones Booleanas."""


from operator import truediv
from re import A


def es_vocal_if(letra: str) -> bool:
"""Toma un string y devuelve un booleano en base a si letra es una vocal o
no.
Expand All @@ -13,7 +17,19 @@ def es_vocal_if(letra: str) -> bool:

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

variable=letra.lower()
if variable=="a":
return True
if variable=="e":
return True
if variable=="i":
return True
if variable=="o":
return True
if variable=="u":
return True

return False

# NO MODIFICAR - INICIO
assert es_vocal_if("a")
Expand All @@ -39,8 +55,10 @@ def es_vocal_if_in(letra: str) -> bool:

Referencia: https://docs.python.org/3/reference/expressions.html#membership-test-operations # noqa: E501
"""


variable=letra.lower()
if variable in "aeiou":
return True
return False
# NO MODIFICAR - INICIO
assert es_vocal_if_in("a")
assert not es_vocal_if_in("b")
Expand All @@ -60,7 +78,9 @@ def es_vocal_in(letra: str) -> bool:
- No utilizar FOR.
- No utilizar listas.
"""

variable=letra.lower()
retorno=variable in "aeiou"
return retorno

# NO MODIFICAR - INICIO
assert es_vocal_in("a")
Expand Down
15 changes: 13 additions & 2 deletions exercises/exercise5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ def sumatoria_basico(n: int) -> int:

Restricción: Utilizar un bucle FOR.
"""

suma=0
for i in range(n+1):
suma=suma+i
return suma

# NO MODIFICAR - INICIO
assert sumatoria_basico(1) == 1
Expand All @@ -23,7 +26,8 @@ def sumatoria_sum(n: int) -> int:
Restricción: No utilizar bucles (FOR, WHILE, etc)
Referencia: https://docs.python.org/3/library/functions.html#sum
"""

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

# NO MODIFICAR - INICIO
assert sumatoria_sum(1) == 1
Expand All @@ -47,6 +51,13 @@ def multiplicar_basico(numeros: Iterable[float]) -> float:
- Utilizar múltiples Return
- No utilizar ELSE
"""
resultado=1
if len(numeros)==0:
return 0
for i in numeros:
resultado=resultado*i

return resultado


# NO MODIFICAR - INICIO
Expand Down
16 changes: 15 additions & 1 deletion exercises/exercise6.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ def numeros_al_final_basico(lista: List[Union[float, str]]) -> List[Union[float,
- Utilizar la función type.
- No utilizar índices.
"""

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

# NO MODIFICAR - INICIO
assert numeros_al_final_basico([3, "a", 1, "b", 10, "j"]) == ["a", "b", "j", 3, 1, 10] # noqa: E501
Expand All @@ -30,6 +38,12 @@ def numeros_al_final_comprension(lista: List[Union[float, str]]) -> List[Union[f
- Utilizar dos comprensiones de listas.
"""

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

# NO MODIFICAR - INICIO
assert numeros_al_final_comprension([3, "a", 1, "b", 10, "j"]) == ["a", "b", "j", 3, 1, 10] # noqa: E501
Expand Down
13 changes: 10 additions & 3 deletions exercises/exercise7.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def superposicion_basico(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool
- Utilizar dos bucles FOR anidados.
- Utilizar dos returns.
"""

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

# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
Expand All @@ -30,7 +34,10 @@ def superposicion_in(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool:
- Utilizar un único bucle FOR.
- Utilizar dos returns.
"""

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

# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
Expand All @@ -52,7 +59,7 @@ def superposicion_any(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool:

Referencia: https://docs.python.org/3/library/functions.html#any
"""

return any([x for x in lista_1 if x in lista_2])

# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
Expand Down
20 changes: 16 additions & 4 deletions exercises/exercise8.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def combinar_basico(nombres: List[str], precios: List[float]) -> Tuple[Any]:
- Utilizar la función range.
- Utilizar índices.
"""

lista=[]
for indice in range(len(nombres)):
lista.append((nombres[indice],precios[indice]))
return tuple(lista)

# NO MODIFICAR - INICIO
respuesta = (
Expand Down Expand Up @@ -51,7 +54,10 @@ def combinar_enumerate(nombres: List[str], precios: List[float], ids: List[int])

Referencia: https://docs.python.org/3/library/functions.html#enumerate
"""

lista=[]
for indice,nombre in enumerate(nombres):
lista.append((nombre,precios[indice],ids[indice]))
return tuple(lista)

# NO MODIFICAR - INICIO
respuesta = (
Expand Down Expand Up @@ -80,7 +86,10 @@ def combinar_zip(nombres: List[str], precios: List[float], ids: List[int]) -> Tu
- No utilizar índices.
Referencia: https://docs.python.org/3/library/functions.html#zip
"""

lista = []
for nombre,precio,id in zip(nombres,precios,ids):
lista.append((nombre,precio,id))
return tuple(lista)

# NO MODIFICAR - INICIO
respuesta = (
Expand Down Expand Up @@ -112,7 +121,10 @@ def combinar_zip_args(*args) -> Tuple[Any]:

Referencia: https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists # noqa: E501
"""

lista=[]
for args in zip(*args):
lista.append((args))
return tuple(lista)

# NO MODIFICAR - INICIO
respuesta = (
Expand Down
17 changes: 12 additions & 5 deletions exercises/exercise9.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ def suma_cubo_pares_for(numeros: Iterable[int]) -> int:
- https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions # noqa: E501
- https://docs.python.org/3/library/functions.html#sum
"""

numeros_cuadrados=[]
suma_pares = 0
for i in numeros:
numeros_cuadrados.append(i ** 3)
for i in numeros_cuadrados:
if (i%2)==0:
suma_pares = suma_pares + i
return suma_pares

# NO MODIFICAR - INICIO
assert suma_cubo_pares_for([1, 2, 3, 4, 5, 6]) == 288
Expand All @@ -33,7 +40,7 @@ def suma_cubo_pares_sum_list(numeros: Iterable[int]) -> int:
- https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions # noqa: E501
- https://docs.python.org/3/library/functions.html#sum
"""

return sum([x ** 3 for x in numeros if not (x%2) != 0 ])

# NO MODIFICAR - INICIO
assert suma_cubo_pares_sum_list([1, 2, 3, 4, 5, 6]) == 288
Expand All @@ -52,15 +59,15 @@ def suma_cubo_pares_sum_list(numeros: Iterable[int]) -> int:
Restricción: Utilizar List, map y lambda y la variable numeros
"""

numeros_al_cubo = # Completar
numeros_al_cubo = list(map(lambda x: x ** 3, numeros))

"""
Escribir una función lambda que permita filtrar todos los elementos pares

Restricción: Utilizar List, filter, lambda y la variable numeros_al_cubo
"""

numeros_al_cubo_pares = # Completar
numeros_al_cubo_pares = list(filter(lambda x: not (x%2) != 0, numeros_al_cubo))


"""
Expand All @@ -71,7 +78,7 @@ def suma_cubo_pares_sum_list(numeros: Iterable[int]) -> int:

from functools import reduce # noqa: E402

suma_numeros_al_cubo_pares = # Completar
suma_numeros_al_cubo_pares = reduce(lambda x,y: x + y, numeros_al_cubo_pares)


# NO MODIFICAR - INICIO
Expand Down
17 changes: 17 additions & 0 deletions exercises/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

from typing import Any, Iterable


def superposicion_basico(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool: # noqa: E501
"""Toma dos listas y devuelve un booleano en base a si tienen al menos 1
elemento en común.

Restricciones:
- Utilizar dos bucles FOR anidados.
- Utilizar dos returns.
"""
for elemento in lista_1:
for elemento2 in lista_2:
if elemento == elemento2:
return True
return False