# Arup Guha
# 2/28/2020
# Written in COP 2930 class to illustrate void functions.

# Prints ch exactly numtimes.
def printChar(ch, numtimes):

    for i in range(numtimes):
        print(ch, end="")

# Prints a forward triangle using the character ch with n rows.
def printForwardTri(ch, n):

    for i in range(1, n+1):
        printChar(ch, i)
        printChar('\n', 1)

# Prints a backward triangle using the character ch with n rows.
def printBackTri(ch, n):

    # i represents the number of stars on each line.
    for i in range(1, n+1):

        numSpaces = n - i
        printChar(' ', numSpaces)
        printChar(ch, i)
        printChar('\n', 1)

# Displays a menu for the user, reads in their choice and returns it.
# If choice isn't valid, the menu is reprompted and choice is reread
# until a valid choice is entered and that is returned.
def menu():

    # Set to a default so loop executes at least once.
    choice = 0

    # Keep going until we get a valid choice.
    while choice < 1 or choice > 3:

        # Print menu, read in choice.
        print("Which option do you want?")
        print("1. Print Forward Triangle.")
        print("2. Print Backward Triangle.")
        print("3. Quit")
        choice = int(input(""))

        # Print error message, if necessary.
        if choice < 1 or choice > 3:
            print("Sorry, that choice is invalid")

    # Return it.
    return choice

def main():

    # Get the user's choice.
    ans = menu()

    # Get the parameters for the design.
    n = int(input("How many rows for your design?\n"))
    ch = input("What character do you want to print it with?")

    # Execute the appropriate design.
    if ans == 1:
        printForwardTri(ch, n)
    elif ans == 2:
        printBackTri(ch, n)

main()
