Created
January 13, 2022 19:24
-
-
Save voith/4b30f0cb68a431c03fff95a43daeea21 to your computer and use it in GitHub Desktop.
Triangle pattern using python
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
# Been a while since I made one of these. | |
# The last time I made one, I was in college. | |
def print_triangle(n: int): | |
for i in range(1, n + 1): | |
digits = len(str(n)) | |
print((" " * (digits + 1)) * (n - i) , end="") | |
for j in range(i): | |
print(" %s" % str(j + 1).rjust(digits, "0"), end="") | |
for j in range(i - 1): | |
print(" %s" % str(i - j - 1).rjust(digits, "0"), end="") | |
print() | |
print_triangle(20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment