'''
Some more samples of nested loops.
Created on Jan 16, 2011

@author: clifton
'''

def trianglePointingDown(width):
    '''Draws a triangle with width stars in the first row, down to 1 star
    in the last row.'''
    print("Printing trianglePointingDown with width: ", width)
    for row in range(width):
        rowWidth = width - row
        # print("*" * rowWidth)
        rowText = ""
        for i in range(rowWidth):
            rowText = rowText + "*"
        print(rowText)

def numberTrianglePointingDown(width):
    '''Draws a triangle with width ones in the first row, down to 1 width
    in the last row.'''
    print("Printing numberTrianglePointingDown with width: ", width)
    for row in range(width):
        rowWidth = width - row
        # print("*" * rowWidth)
        rowText = ""
        for i in range(rowWidth):
            nextNum = str(row + 1)
            rowText = rowText + nextNum[-1]
        print(rowText)

def countingTrianglePointingDown(width):
    '''Draws a triangle with width ones in the first row, down to 1 width
    in the last row.'''
    print("Printing numberTrianglePointingDown with width: ", width)
    for row in range(width):
        rowWidth = width - row
        # print("*" * rowWidth)
        rowText = ""
        for i in range(1,rowWidth+1):
            rowText = rowText + str(i)
        print(rowText)

def isocelesTriangle(width):
    '''Draws an isoceles triangle with horizontal base and points at
    upper left and lower right.'''
    print("Running isocelesTriangle with width ", width)
    if width % 2 == 0:
        print("Must be an odd width")
        return
    maxNumberOfStars = width // 2 + 1
    #print(maxNumberOfStars)
    for row in range(maxNumberOfStars):
        #print(row)
        rowText = ""
        for i in range(row):
            rowText = rowText + " "
        #print(rowText + "#")
        #rowText = ""
        for i in range(row+1):
            rowText = rowText + "*"
        print(rowText)
        
def main():
    '''Tests some nested loop functions.'''
    trianglePointingDown(4)
    trianglePointingDown(12)
    trianglePointingDown(1)
    numberTrianglePointingDown(4)
    numberTrianglePointingDown(1)
    numberTrianglePointingDown(9)
    countingTrianglePointingDown(4)
    countingTrianglePointingDown(9)
    countingTrianglePointingDown(1)
    isocelesTriangle(4)
    isocelesTriangle(7)
    isocelesTriangle(13)
    isocelesTriangle(1)
    numberTrianglePointingDown(13)
    numberTrianglePointingDown(115)


if __name__ == '__main__':
    main()