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
11 changes: 11 additions & 0 deletions exercises/exercise1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Bloque IF, operadores lógicos, función max y operador ternario."""


from ast import arg
from re import A


def maximo_basico(a: float, b: float) -> float:
"""Toma dos números y devuelve el mayor.

Expand All @@ -9,6 +13,10 @@ def maximo_basico(a: float, b: float) -> float:
- No utilizar ELSE
- No utilizar la función max
"""
if a > b:
return a
if b > a:
return b


# NO MODIFICAR - INICIO
Expand All @@ -24,6 +32,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
"""
resultado = max(a, b)
return resultado


# NO MODIFICAR - INICIO
Expand All @@ -39,6 +49,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
Expand Down
16 changes: 16 additions & 0 deletions exercises/exercise2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"""


from ast import arg
from this import d


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

Expand All @@ -14,6 +18,12 @@ def maximo_encadenado(a: float, b: float, c: float) -> float:
Referencia: https://docs.python.org/3/reference/expressions.html#comparisons # noqa: E501
"""

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


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

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

resultado = max(a, b, c, d)
return resultado


# NO MODIFICAR - INICIO
assert maximo_cuadruple(1, 10, 5, -5) == 10
Expand All @@ -55,6 +68,9 @@ def maximo_arbitrario(*args) -> float:
Referencia: https://docs.python.org/3/tutorial/controlflow.html#arbitrary-argument-lists # noqa: E501
"""

resultado = max(*args)
return resultado


# NO MODIFICAR - INICIO
assert maximo_arbitrario(1, 10, 5, -5) == 10
Expand Down
15 changes: 13 additions & 2 deletions exercises/exercise3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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
Expand All @@ -38,8 +45,12 @@ def operacion_multiple(a: float, b: float, multiplicar: bool) -> Union[float, st
- Utilizar 2 IF.
- No Utilizar IF anidados.
- No utilizar ELIF ni ELSE.
- No utilizar AND ni OR.
"""
- 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
Expand Down
19 changes: 18 additions & 1 deletion exercises/exercise4.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +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
Expand Down Expand Up @@ -40,6 +52,10 @@ def es_vocal_if_in(letra: str) -> bool:
Referencia: https://docs.python.org/3/reference/expressions.html#membership-test-operations # noqa: E501
"""

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


# NO MODIFICAR - INICIO
assert es_vocal_if_in("a")
Expand All @@ -61,8 +77,9 @@ def es_vocal_in(letra: str) -> bool:
- No utilizar listas.
"""

return letra == letra.lower() in "a" "e" "i" "o" "u"

# NO MODIFICAR - INICIO
# NO MODIFICAR - INICIO
assert es_vocal_in("a")
assert not es_vocal_in("b")
assert es_vocal_in("A")
Expand Down
17 changes: 16 additions & 1 deletion exercises/exercise5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ def sumatoria_basico(n: int) -> int:

Restricción: Utilizar un bucle FOR.
"""
sumatoria = 0

for i in range(1, n+1):
sumatoria += i
return sumatoria

# NO MODIFICAR - INICIO
# NO MODIFICAR - INICIO
assert sumatoria_basico(1) == 1
assert sumatoria_basico(100) == 5050
# NO MODIFICAR - FIN
Expand All @@ -23,6 +27,9 @@ def sumatoria_sum(n: int) -> int:
Restricción: No utilizar bucles (FOR, WHILE, etc)
Referencia: https://docs.python.org/3/library/functions.html#sum
"""
# list(range(n+1))
suma = sum(range(n+1))
return suma


# NO MODIFICAR - INICIO
Expand All @@ -47,6 +54,14 @@ def multiplicar_basico(numeros: Iterable[float]) -> float:
- Utilizar múltiples Return
- No utilizar ELSE
"""
if len(numeros) == 0:
return 0

productos = float(1)

for i in numeros:
productos = productos * i
return productos


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

for i in lista:
if type(i) == int:
listaEnteros.append(i)
else:
listaStrings.append(i)
listaStrings.extend(listaEnteros)
return listaStrings


# NO MODIFICAR - INICIO
Expand All @@ -29,6 +39,11 @@ def numeros_al_final_comprension(lista: List[Union[float, str]]) -> List[Union[f
- No utilizar bucles.
- Utilizar dos comprensiones de listas.
"""
numbers = [n for n in lista if type(n) is int]
strings = [s for s in lista if type(s) is str]

strings.extend(numbers)
return strings


# NO MODIFICAR - INICIO
Expand Down
12 changes: 12 additions & 0 deletions exercises/exercise7.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Any y Sets."""

from this import s
from typing import Any, Iterable


Expand All @@ -11,6 +12,11 @@ def superposicion_basico(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool
- Utilizar dos bucles FOR anidados.
- Utilizar dos returns.
"""
for i in lista_1:
for j in lista_2:
if (i == j):
return True
return False


# NO MODIFICAR - INICIO
Expand All @@ -30,6 +36,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
Expand All @@ -52,6 +62,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([n for n in lista_1 if n in lista_2])


# NO MODIFICAR - INICIO
Expand All @@ -73,6 +84,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 not set(lista_1).isdisjoint(set(lista_2))


# NO MODIFICAR - INICIO
Expand Down
28 changes: 28 additions & 0 deletions exercises/exercise8.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ def combinar_basico(nombres: List[str], precios: List[float]) -> Tuple[Any]:
- Utilizar la función range.
- Utilizar índices.
"""
"""
for indice, (nombres, precios) in zip(nombres, precios):
respuesta = (
print(f"({nombres}, {precios})")
)
"""

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


# NO MODIFICAR - INICIO
Expand Down Expand Up @@ -52,6 +63,12 @@ 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, producto in enumerate(nombres):
lista.append((producto, precios[indice], ids[indice]))
return tuple(lista)


# NO MODIFICAR - INICIO
respuesta = (
Expand Down Expand Up @@ -80,6 +97,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
"""
listado_final = []
for (nombres, precios, ids) in zip(nombres, precios, ids):
listado_parcial = (nombres, precios, ids)
print(listado_parcial)
listado_final.append(listado_parcial)
return tuple(listado_final)


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

Referencia: https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists # noqa: E501
"""
lista_final = []
for componentes in zip(*args):
lista_parcial = (componentes)
lista_final.append(lista_parcial)
return tuple(lista_final)


# NO MODIFICAR - INICIO
Expand Down
21 changes: 16 additions & 5 deletions exercises/exercise9.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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
assert suma_cubo_pares_for([1, 2, 3, 4, 5, 6]) == 288
Expand All @@ -33,7 +43,8 @@ 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