Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Last active February 5, 2016 16:38
Show Gist options
  • Select an option

  • Save narenaryan/c8d9015e896838243d31 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/c8d9015e896838243d31 to your computer and use it in GitHub Desktop.
Print numbers in side triangle form
def print_figure(n):
for i in range(1, n+1) + list(reversed(range(1, n))):
print ''.join([str(i) for i in range(1, i+1)])
print_figure(4)
def print_recurse_figure(m):
def print_figure(n):
if n == 1:
print 1
return
elif n > 1:
print ''.join([str(i) for i in range(1, n+1)])
print_figure(n - 1)
elif n < 0:
print ''.join([str(i) for i in range(1, m+n+1)])
print_figure(n + 1)
print_figure(-m)
print_figure(m)
print_recurse_figure(4)
@diek
Copy link

diek commented Feb 5, 2016

@rautamiekka this shows your lack of understanding of Python, it works fine in Python 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment