Skip to content

Instantly share code, notes, and snippets.

@voith
Created January 13, 2022 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voith/4b30f0cb68a431c03fff95a43daeea21 to your computer and use it in GitHub Desktop.
Save voith/4b30f0cb68a431c03fff95a43daeea21 to your computer and use it in GitHub Desktop.
Triangle pattern using python
# 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