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


from re import A


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

Expand All @@ -12,6 +15,11 @@ def maximo_basico(a: float, b: float) -> float:


# NO MODIFICAR - INICIO

if a > b:
return a
if b > a:
return b
assert maximo_basico(10, 5) == 10
assert maximo_basico(9, 18) == 18
# NO MODIFICAR - FIN
Expand All @@ -25,8 +33,13 @@ def maximo_libreria(a: float, b: float) -> float:
Referencia: https://docs.python.org/3/library/functions.html#max
"""


# NO MODIFICAR - INICIO

if a > b:
return max(a,b)
if b > a:
return max(a,b)

assert maximo_libreria(10, 5) == 10
assert maximo_libreria(9, 18) == 18
# NO MODIFICAR - FIN
Expand All @@ -42,6 +55,8 @@ def maximo_ternario(a: float, b: float) -> float:


# NO MODIFICAR - INICIO
return a if (a>b) else b

assert maximo_ternario(10, 5) == 10
assert maximo_ternario(9, 18) == 18
# NO MODIFICAR - FIN
17 changes: 16 additions & 1 deletion exercises/exercise2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"""


from ast import Compare


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

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


######### FALTA REVISAR
# NO MODIFICAR - INICIO
Compare(a | b | c)
if a > b:
return max(a,b)
if b > c:
return max(b,c)

assert maximo_encadenado(1, 10, 5) == 10
assert maximo_encadenado(5, 10, 1) == 10
assert maximo_encadenado(5, 10, 5) == 10
Expand All @@ -40,6 +49,9 @@ def maximo_cuadruple(a: float, b: float, c: float, d: float) -> float:


# NO MODIFICAR - INICIO

return max(a, b, c, d)

assert maximo_cuadruple(1, 10, 5, -5) == 10
assert maximo_cuadruple(4, 9, 18, 6) == 18
assert maximo_cuadruple(24, 9, 18, 20) == 24
Expand All @@ -57,6 +69,9 @@ def maximo_arbitrario(*args) -> float:


# NO MODIFICAR - INICIO

return max(*args)

assert maximo_arbitrario(1, 10, 5, -5) == 10
assert maximo_arbitrario(4, 9, 18, 6) == 18
assert maximo_arbitrario(24, 9, 18, 20) == 24
Expand Down
21 changes: 19 additions & 2 deletions exercises/exercise3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Único return vs múltiples return."""

from operator import truediv
from typing import Union
from xmlrpc.server import MultiPathXMLRPCServer


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


# NO MODIFICAR - INICIO
if multiplicar:
result = a*b
elif b!=0:
result = a/b
else:
result = "Operación no válida"
print(result)
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 +52,14 @@ def operacion_multiple(a: float, b: float, multiplicar: bool) -> Union[float, st


# NO MODIFICAR - INICIO

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


assert operacion_multiple(1, 1, True) == 1
assert operacion_multiple(1, 1, False) == 1
assert operacion_multiple(25, 5, True) == 125
Expand Down
29 changes: 28 additions & 1 deletion exercises/exercise4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""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.
Expand All @@ -16,6 +15,19 @@ def es_vocal_if(letra: str) -> bool:


# NO MODIFICAR - INICIO
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

assert es_vocal_if("a")
assert not es_vocal_if("b")
assert es_vocal_if("A")
Expand All @@ -42,6 +54,13 @@ def es_vocal_if_in(letra: str) -> bool:


# NO MODIFICAR - INICIO
letra = letra.lower()
vocales = 'aeiou'

if (letra in vocales):
return True
return False

assert es_vocal_if_in("a")
assert not es_vocal_if_in("b")
assert es_vocal_if_in("A")
Expand All @@ -63,6 +82,14 @@ def es_vocal_in(letra: str) -> bool:


# NO MODIFICAR - INICIO
es_vocal=False
letra == letra.lower()
vocales = 'aeiou'
while letra in vocales:
es_vocal=True
break;
return es_vocal

assert es_vocal_in("a")
assert not es_vocal_in("b")
assert es_vocal_in("A")
Expand Down
19 changes: 16 additions & 3 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

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

assert sumatoria_basico(1) == 1
assert sumatoria_basico(100) == 5050
# NO MODIFICAR - FIN
Expand All @@ -21,9 +27,10 @@ def sumatoria_sum(n: int) -> int:
"""Re-Escribir utilizando la función sum.

Restricción: No utilizar bucles (FOR, WHILE, etc)
Referencia: https://docs.python.org/3/library/functions.html#sum
Referencia: https://docs.python.org/3/library/functions.html#sum sum(Iterable,start=0)
"""


return sum(range(n+1))

# NO MODIFICAR - INICIO
assert sumatoria_sum(1) == 1
Expand All @@ -38,7 +45,7 @@ def sumatoria_sum(n: int) -> int:


def multiplicar_basico(numeros: Iterable[float]) -> float:
"""Toma un lista de números y devuelve el producto todos los númereos. Si
"""Toma un lista de números y devuelve el producto todos los números. Si
la lista está vacia debe devolver 0.

Restricciones:
Expand All @@ -47,6 +54,12 @@ def multiplicar_basico(numeros: Iterable[float]) -> float:
- Utilizar múltiples Return
- No utilizar ELSE
"""
if (len(numeros)==0):
return 0
total = 1
for i in numeros:
total = total * i
return total


# NO MODIFICAR - INICIO
Expand Down
21 changes: 18 additions & 3 deletions exercises/exercise6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Union


lista=[3, "a", 1, "b", 10, "j"]
def numeros_al_final_basico(lista: List[Union[float, str]]) -> List[Union[float, str]]: # noqa: E501
"""Toma una lista de enteros y strings y devuelve una lista con todos los
elementos numéricos al final.
Expand All @@ -12,16 +13,25 @@ def numeros_al_final_basico(lista: List[Union[float, str]]) -> List[Union[float,
- Utilizar la función type.
- No utilizar índices.
"""

lista1=[]
for i in lista:
if type(i) == int:
lista1.append(i)
elif type(i)== str:
lista1.insert(0,i)
print(lista1)
return lista1

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

# NO MODIFICAR - FIN


###############################################################################


#DIAPO 12 funciones
from typing import List, Union
def numeros_al_final_comprension(lista: List[Union[float, str]]) -> List[Union[float, str]]: # noqa: E501
"""Re-escribir utilizando comprensión de listas.

Expand All @@ -30,7 +40,12 @@ def numeros_al_final_comprension(lista: List[Union[float, str]]) -> List[Union[f
- Utilizar dos comprensiones de listas.
"""


numeros=[]
letras=[]
lista = [i for i in lista if type(i) ==int]
lista = [i for i in lista if type(i) == str]
suma = letras + numeros
print(suma)
# NO MODIFICAR - INICIO
assert numeros_al_final_comprension([3, "a", 1, "b", 10, "j"]) == ["a", "b", "j", 3, 1, 10] # noqa: E501
# NO MODIFICAR - FIN
28 changes: 20 additions & 8 deletions exercises/exercise7.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@

from typing import Any, Iterable


test_list = [1, "hello", 35.20]
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 bucles FOR anidados.
- Utilizar dos returns.
"""


bool = 0
for x in lista_1:
for y in lista_2:
if x == y:
bool = True
if (not bool):
return False
else:
return True

# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
assert superposicion_basico(test_list, (2, "world", 35.20))
Expand All @@ -21,16 +29,19 @@ def superposicion_basico(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool


###############################################################################


from typing import Any, Iterable
test_list = [1, "hello", 35.20]
def superposicion_in(lista_1: Iterable[Any], lista_2: Iterable[Any]) -> bool:
"""Re-Escribir utilizando un sólo bucle y el operador IN.

Restricciones:
- 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]
Expand All @@ -52,7 +63,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_2 for i in lista_1)

# NO MODIFICAR - INICIO
test_list = [1, "hello", 35.20]
Expand All @@ -74,6 +85,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 bool (set(lista_1) & set(lista_2))

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