How do I make a triangle using a recursive function like this:
def triangle(3):
And the triangle should look like this:
1
1 1
1 2 1
And so on.
How do I make a triangle using a recursive function like this:
def triangle(3):
And the triangle should look like this:
1
1 1
1 2 1
And so on.
You can do something like this.
n=4
def triangle(n):
if n==0:
return
num=11**(triangle.n-n)
print "{}{}".format(" "*n, " ".join(list(str(num))))
triangle(n-1)
triangle.n = n
triangle(n)
Output:
1
1 1
1 2 1
1 3 3 1