[Solved] patterns in python-complex


You can use the following code:

def upanddown(n):
    return range(1, n) + range(n, 0, -1)

def triangle(rows):
    for num in xrange(1, rows + 1):
        print ' '.join(map(str, upanddown(num))).center(rows * 4 - 3)

rows = input("Number of rows: ")
triangle(rows)

Output:

Number of rows: 4
      1      
    1 2 1    
  1 2 3 2 1  
1 2 3 4 3 2 1

5

solved patterns in python-complex