File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Retos/Reto #20 - LA TRIFUERZA [Media]/python Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ ¡El nuevo "The Legend of Zelda: Tears of the Kingdom" ya está disponible!
3+
4+ Crea un programa que dibuje una Trifuerza de "Zelda"
5+ formada por asteriscos.
6+ - Debes indicarle el número de filas de los triángulos con un entero positivo (n).
7+ - Cada triángulo calculará su fila mayor utilizando la fórmula 2n-1.
8+
9+ Ejemplo: Trifuerza 2
10+
11+ *
12+ ***
13+ * *
14+ *** ***
15+ """
16+
17+ def draw_triforce (n : int ) -> str :
18+ """
19+ Genera una Trifuerza inspirada en "The Legend of Zelda" utilizando asteriscos.
20+
21+ La Trifuerza está compuesta por tres triángulos equiláteros:
22+ uno superior y dos en la base. Cada triángulo tiene como fila más ancha
23+ la longitud calculada con la fórmula ``2n - 1``.
24+
25+ Args:
26+ n (int): Número de filas de cada triángulo. Debe ser un entero positivo.
27+
28+ Returns:
29+ str: El patrón de la Trifuerza en forma de cadena.
30+
31+ Raises:
32+ TypeError: Si el valor proporcionado no es un entero.
33+ ValueError: Si el número es negativo.
34+ """
35+ if not isinstance (n , int ):
36+ raise TypeError ("Solo se admiten enteros positivos." )
37+ if n <= 0 :
38+ raise ValueError ("El número de filas debe ser un entero positivo." )
39+
40+ lines = []
41+ for i in range (n ):
42+ lines .append (" " * (2 * n - i - 1 ) + "*" * (2 * i + 1 ))
43+ for i in range (n ):
44+ left = " " * (n - i - 1 ) + "*" * (2 * i + 1 )
45+ right = "*" * (2 * i + 1 )
46+ middle = " " * (2 * (n - i ) - 1 )
47+ lines .append (f"{ left } { middle } { right } " )
48+
49+ return "\n " .join (lines )
50+
51+
52+ if __name__ == "__main__" :
53+ print (draw_triforce (5 ))
You can’t perform that action at this time.
0 commit comments