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
13 changes: 10 additions & 3 deletions exercises/exercise1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@


def maximo_basico(a: float, b: float) -> float:

"""Toma dos números y devuelve el mayor.

Restricciones:
- Utilizar IF
- No utilizar ELSE
- No utilizar la función max
"""

if (a>b):
print("te paso el a")
return a
print("te paso el b")
return b

# NO MODIFICAR - INICIO
assert maximo_basico(10, 5) == 10
Expand All @@ -25,6 +30,8 @@ def maximo_libreria(a: float, b: float) -> float:
Referencia: https://docs.python.org/3/library/functions.html#max
"""

maximo_libreria=max(a, b)
return maximo_libreria

# NO MODIFICAR - INICIO
assert maximo_libreria(10, 5) == 10
Expand All @@ -39,8 +46,8 @@ 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
"""


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

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

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


# NO MODIFICAR - INICIO
assert maximo_encadenado(1, 10, 5) == 10
Expand All @@ -38,7 +43,9 @@ def maximo_cuadruple(a: float, b: float, c: float, d: float) -> float:

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


maximo_cuadruple=max(a,b,c,d)
print(maximo_cuadruple)
return maximo_cuadruple
# NO MODIFICAR - INICIO
assert maximo_cuadruple(1, 10, 5, -5) == 10
assert maximo_cuadruple(4, 9, 18, 6) == 18
Expand All @@ -54,7 +61,8 @@ 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
18 changes: 15 additions & 3 deletions exercises/exercise3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ def operacion_basica(a: float, b: float, multiplicar: bool) -> Union[float, str]
- Si multiplicar es True: devuelve la multiplicación entre a y b.
- Si multiplicar es False: devuelve la division entre a y b.
- Si multiplicar es False y b es cero: devuelve "Operación no válida".

Restricciones:
- Utilizar un único return.
- Utilizar IF con ELIF con ELSE.
- No utilizar AND ni OR.
"""


var=0
if multiplicar == True:
var=a*b
elif b==0:
var="Operación no válida"
else:
var=a/b
return var
# NO MODIFICAR - INICIO
assert operacion_basica(1, 1, True) == 1
assert operacion_basica(1, 1, False) == 1
Expand All @@ -40,6 +45,13 @@ 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
elif b==0:
return "Operación no válida"
else:
return a/b



# NO MODIFICAR - INICIO
Expand Down
27 changes: 24 additions & 3 deletions exercises/exercise4.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ def es_vocal_if(letra: str) -> bool:

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

letra = letra.lower()
if(letra == 'a'):
return True
elif (letra == 'e'):
return True
elif (letra == 'i'):
return True
elif (letra == 'o'):
return True
elif (letra == 'u'):
return True
return False

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

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

letra = letra.lower()
voc = "aeiou"
if (letra in voc):
return True
return False

# NO MODIFICAR - INICIO
assert es_vocal_if_in("a")
Expand All @@ -60,7 +75,13 @@ def es_vocal_in(letra: str) -> bool:
- No utilizar FOR.
- No utilizar listas.
"""

es_vocal_in = False
letra = letra.lower()
voc = "aeiou"
while letra in voc:
es_vocal_in = True
break;
return es_vocal_in

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

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


suma = 0
for i in range(n+1):
suma += i
return suma
# NO MODIFICAR - INICIO
assert sumatoria_basico(1) == 1
assert sumatoria_basico(100) == 5050
Expand All @@ -23,7 +25,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
"""


return sum(range(1, n+1))

# NO MODIFICAR - INICIO
assert sumatoria_sum(1) == 1
Expand All @@ -47,7 +50,12 @@ def multiplicar_basico(numeros: Iterable[float]) -> float:
- Utilizar múltiples Return
- No utilizar ELSE
"""

multip= 1
if numeros ==[]:
return 0
for n in numeros:
multip*=n
return multip

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

listaNums = []
listaLetras = []
for i in lista:
if type(i) == str:
listaLetras.append(i)
else:
listaNums.append(i)
lista = listaLetras + listaNums
return lista
print(lista)

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

listaNums = []
listaLetras = []
listaNums = [i for i in lista if type(i) == int]
listaLetras = [i for i in lista if type(i) == str]
lista = listaLetras + listaNums
return lista

# NO MODIFICAR - INICIO
assert numeros_al_final_comprension([3, "a", 1, "b", 10, "j"]) == ["a", "b", "j", 3, 1, 10] # noqa: E501
Expand Down
19 changes: 13 additions & 6 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 n in lista_1:
for i in lista_2:
if n == i:
return True
return False

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


for i in lista_1:
if i in lista_2:
return True
return False
# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
assert superposicion_in(test_list, (2, "world", 35.20))
Expand All @@ -52,8 +58,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 ( i in lista_1 for i in lista_2)
# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
assert superposicion_any(test_list, (2, "world", 35.20))
Expand All @@ -73,7 +78,9 @@ def superposicion_set(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool:

Referencia: https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset # noqa: E501
"""

a = set(lista_1)
b = set(lista_2)
return bool (a.intersection(b))

# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
Expand Down
25 changes: 18 additions & 7 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 i in range(3):
lista.append((nombres[i], precios[i]))
return tuple(lista)

# NO MODIFICAR - INICIO
respuesta = (
Expand Down Expand Up @@ -51,8 +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 = (
("ventana", 100.48, 6852),
Expand Down Expand Up @@ -80,8 +85,12 @@ 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 n in zip(nombres, precios, ids):
lista_1 = [nombres, precios, ids]
lista.append(tuple(lista_1))
print(lista_1)
return tuple(lista)
# NO MODIFICAR - INICIO
respuesta = (
("ventana", 100.48, 6852),
Expand Down Expand Up @@ -112,8 +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 arg in zip(*args):
lista.append(arg)
return tuple(lista)
# NO MODIFICAR - INICIO
respuesta = (
("ventana", 100.48, 6852, "hogar", True),
Expand Down
16 changes: 13 additions & 3 deletions exercises/exercise9.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ 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
"""
list=[]
for n in numeros:
list.append(pow(n, 3))
sumacubos=0
for n in list:
if n %2 == 0:
sumacubos += n
print(sumacubos)
return sumacubos


# NO MODIFICAR - INICIO
Expand All @@ -33,7 +42,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((pow(i,3)) for i in numeros if i % 2 == 0)

# NO MODIFICAR - INICIO
assert suma_cubo_pares_sum_list([1, 2, 3, 4, 5, 6]) == 288
Expand All @@ -53,14 +62,15 @@ def suma_cubo_pares_sum_list(numeros: Iterable[int]) -> int:
"""

numeros_al_cubo = # Completar

numeros_al_cubo = list(map(lambda i: i ** 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
list(filter(lambda i: i % 2 == 0, numeros_al_cubo))


"""
Expand All @@ -72,7 +82,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 i, x: i + x, numeros_al_cubo_pares)

# NO MODIFICAR - INICIO
assert numeros_al_cubo == [1, 8, 27, 64, 125, 216]
Expand Down
Loading