|
29 | 29 |
|
30 | 30 | # No import needed for None type annotation |
31 | 31 |
|
32 | | -def pyramid(n: int) -> None: |
33 | | - """Prints a pyramid pattern of height n.""" |
34 | | - for i in range(n): |
35 | | - print(" " * (n - i - 1) + "*" * (2 * i + 1)) |
| 32 | +def pyramid(height: int) -> None: |
| 33 | + """Prints a pyramid pattern of the specified height.""" |
| 34 | + for i in range(height): |
| 35 | + print(" " * (height - i - 1) + "*" * (2 * i + 1)) |
36 | 36 |
|
37 | 37 |
|
38 | | -def inverted_pyramid(n: int) -> None: |
39 | | - """Prints an inverted pyramid pattern of height n.""" |
40 | | - for i in range(n - 1, -1, -1): |
41 | | - print(" " * (n - i - 1) + "*" * (2 * i + 1)) |
| 38 | +def inverted_pyramid(height: int) -> None: |
| 39 | + """Prints an inverted pyramid pattern of the specified height.""" |
| 40 | + for i in range(height - 1, -1, -1): |
| 41 | + print(" " * (height - i - 1) + "*" * (2 * i + 1)) |
42 | 42 |
|
43 | 43 |
|
44 | | -def diamond(n: int) -> None: |
45 | | - """Prints a diamond pattern of height n.""" |
46 | | - pyramid(n) |
47 | | - for i in range(n - 2, -1, -1): |
48 | | - print(" " * (n - i - 1) + "*" * (2 * i + 1)) |
| 44 | +def diamond(height: int) -> None: |
| 45 | + """Prints a diamond pattern of the specified height.""" |
| 46 | + pyramid(height) |
| 47 | + for i in range(height - 2, -1, -1): |
| 48 | + print(" " * (height - i - 1) + "*" * (2 * i + 1)) |
49 | 49 |
|
50 | 50 |
|
51 | 51 | if __name__ == "__main__": |
|
0 commit comments