forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
Retos/Reto #29 - EL CARÁCTER INFILTRADO [Fácil]/python/jpirulo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
||
|