Skip to content

Instantly share code, notes, and snippets.

@JoaoGFarias
Created May 4, 2014 03:02
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 JoaoGFarias/701a3f518038130117d4 to your computer and use it in GitHub Desktop.
Save JoaoGFarias/701a3f518038130117d4 to your computer and use it in GitHub Desktop.
A simple script that prints a beatiful triangle using a recursion (printLine) inside other recursion (printTriangle)
#!/usr/local/bin/python2.7
import sys
def printLine(n):
sys.stdout.write(str(n))
if n != 1:
sys.stdout.write(' ')
printLine(n-1)
else:
sys.stdout.write("\n")
def printTriangle(n):
printLine(n)
if n == 1:
return None
else:
printTriangle(n-1)
printTriangle(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment