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
15 changes: 9 additions & 6 deletions exercises/exercise1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@


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

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

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


# NO MODIFICAR - INICIO
assert maximo_basico(10, 5) == 10
assert maximo_basico(9, 18) == 18
Expand All @@ -24,8 +26,8 @@ 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
"""


maximo_libreria = max(a,b)
return maximo_libreria
# NO MODIFICAR - INICIO
assert maximo_libreria(10, 5) == 10
assert maximo_libreria(9, 18) == 18
Expand All @@ -36,11 +38,12 @@ def maximo_libreria(a: float, b: float) -> float:


def maximo_ternario(a: float, b: float) -> float:
maximo_ternario= a if a>b else b;
return maximo_ternario
"""Re-escribir utilizando el operador ternario.
Referencia: https://docs.python.org/3/reference/expressions.html#conditional-expressions # noqa: E501
"""


# NO MODIFICAR - INICIO
assert maximo_ternario(10, 5) == 10
assert maximo_ternario(9, 18) == 18
Expand Down
12 changes: 12 additions & 0 deletions exercises/exercise2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
"""


from ast import arg


def maximo_encadenado(a: float, b: float, c: float) -> float:
if c < b > a:
return b
if a < c > b:
return c
return a
"""Toma 3 números y devuelve el máximo.

Restricciones:
Expand Down Expand Up @@ -37,6 +45,8 @@ 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"""
maximo_cuadruple=max(a, b, c, d)
return maximo_cuadruple


# NO MODIFICAR - INICIO
Expand All @@ -55,6 +65,8 @@ def maximo_arbitrario(*args) -> float:
Referencia: https://docs.python.org/3/tutorial/controlflow.html#arbitrary-argument-lists # noqa: E501
"""




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

from operator import truediv
from typing import Union


def operacion_basica(a: float, b: float, multiplicar: bool) -> Union[float, str]: # noqa: E501
"""Toma dos números (a, b) y un booleano (multiplicar):
- Si multiplicar es True: devuelve la multiplicación entre a y b.
Expand All @@ -14,7 +13,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:
resultado = a*b
elif b==0:
resultado = "Operación no válida"
else:
resultado = a/b
return resultado

# NO MODIFICAR - INICIO
assert operacion_basica(1, 1, True) == 1
Expand All @@ -39,7 +44,18 @@ def operacion_multiple(a: float, b: float, multiplicar: bool) -> Union[float, st
- No Utilizar IF anidados.
- No utilizar ELIF ni ELSE.
- No utilizar AND ni OR.
- 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".
"""
if multiplicar==True:
return a*b
if multiplicar==False:
try:
return a/b
except ZeroDivisionError:
return "Operación no válida"



# NO MODIFICAR - INICIO
Expand Down
13 changes: 12 additions & 1 deletion 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
if letra == "e":
return True
if letra == "i":
return True
if letra == "o":
return True
if letra == "u":
return True
return False

# NO MODIFICAR - INICIO
assert es_vocal_if("a")
Expand Down
14 changes: 14 additions & 0 deletions exercises/exercise5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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
Expand All @@ -23,6 +27,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
"""
lista=list(range(1,n+1))
return sum(lista)


# NO MODIFICAR - INICIO
Expand All @@ -47,6 +53,14 @@ def multiplicar_basico(numeros: Iterable[float]) -> float:
- Utilizar múltiples Return
- No utilizar ELSE
"""
producto=1
lista=list(numeros)
if lista==[]:
return 0
if lista != []:
for i in lista:
producto = i*producto
return producto


# NO MODIFICAR - INICIO
Expand Down
4 changes: 2 additions & 2 deletions exercises/exercise7.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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(check in lista_2 for check in lista_1)


# NO MODIFICAR - INICIO
Expand All @@ -73,8 +74,7 @@ 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
"""


return set(lista_2) & set(lista_1)
# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
assert superposicion_set(test_list, (2, "world", 35.20))
Expand Down
5 changes: 4 additions & 1 deletion exercises/exercise8.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ 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
"""

respuesta = tuple(zip(nombre_articulos, precio_articulos, id_articulos))
return respuesta

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

Referencia: https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists # noqa: E501
"""
respuesta = tuple(zip(nombre_articulos, precio_articulos, id_articulos, categoria_articulos, importado_articulos))
return respuesta


# NO MODIFICAR - INICIO
Expand Down
19 changes: 15 additions & 4 deletions exercises/exercise9.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ 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
"""
cubos=[]
for x in numeros:
y= x**3
cubos.append(y)

suma=0
for y in cubos:
if (y % 2 == 0):
suma = suma+y

return suma


# NO MODIFICAR - INICIO
Expand All @@ -33,7 +44,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 (x**3)%2 == 0)

# NO MODIFICAR - INICIO
assert suma_cubo_pares_sum_list([1, 2, 3, 4, 5, 6]) == 288
Expand All @@ -52,15 +63,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: x%2==0, numeros_al_cubo))


"""
Expand All @@ -71,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 x,y: x+y, numeros_al_cubo_pares)


# NO MODIFICAR - INICIO
Expand Down