Last active
February 5, 2016 16:38
-
-
Save narenaryan/c8d9015e896838243d31 to your computer and use it in GitHub Desktop.
Print numbers in side triangle form
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rautamiekka this shows your lack of understanding of Python, it works fine in Python 2.