Skip to content

Commit

Permalink
Reto mouredev#29 python
Browse files Browse the repository at this point in the history
  • Loading branch information
jpirulo committed Jul 30, 2023
1 parent 0d9c842 commit 49b97f0
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from termcolor import colored

class ComparadorCadenas:
def __init__(self, cadena1, cadena2):
self.cadena1 = cadena1
self.cadena2 = cadena2
self.longitud = len(cadena1)
self.diferencias = []

def encontrar_diferencias(self):
for i in range(self.longitud):
if self.cadena1[i] != self.cadena2[i]:
self.diferencias.append(colored(self.cadena2[i], 'red'))
else:
self.diferencias.append(self.cadena2[i])

def mostrar_diferencias(self):
print("Diferencias: " + " ".join(self.diferencias))

def resaltar_diferencias(func):
def wrapper(*args, **kwargs):
comparador = func(*args, **kwargs)
comparador.encontrar_diferencias()
comparador.mostrar_diferencias()
return wrapper

@resaltar_diferencias
def obtener_cadenas():
cadena1 = input("Ingrese la primera cadena de texto: ")
cadena2 = input("Ingrese la segunda cadena de texto: ")
return ComparadorCadenas(cadena1, cadena2)

if __name__ == "__main__":
obtener_cadenas()
45 changes: 45 additions & 0 deletions Retos/Reto #30 - EL TECLADO T9 [Media]/python/jpirulo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from termcolor import colored

def uppercase_decorator(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return colored(result.upper(), 'green')
return wrapper

class T9Converter:
def __init__(self, input_t9):
self.input_t9 = input_t9
self.t9_mapping = {
'2': 'ABC', '3': 'DEF', '4': 'GHI',
'5': 'JKL', '6': 'MNO', '7': 'PQRS',
'8': 'TUV', '9': 'WXYZ'
}

@uppercase_decorator
def convert(self):
result_text = ''
blocks = self.input_t9.split('-')

for block in blocks:
if block and block.isdigit():
digit = block[0]
count = len(block)
if digit in self.t9_mapping:
index = (count - 1) % len(self.t9_mapping[digit])
result_text += self.t9_mapping[digit][index]
else:
result_text += digit

return result_text

if __name__ == "__main__":
input_t9 = "6-2-66-88-33-555"

t9_converter = T9Converter(input_t9)
converted_text = t9_converter.convert()

print("Salida:", converted_text)




0 comments on commit 49b97f0

Please sign in to comment.