from typing import TextIO

def write_ascii_triangle(outfile: TextIO, block: str, sidelength: int) -> None:
    """Write an ascii isosceles right triangle using block that is sidelength
    characters wide and high to outfile. The right angle should be in the
    upper-left corner. 

    Precondition: len(block) == 1

    For example, given block="@" and sidelength=4, the
    following should be written to the file:
    
    @@@@
    @@@
    @@
    @
    """
    
    for length in range(sidelength, 0, -1):
        outfile.write(block * length + '\n')

    # another option:
    #length = sidelength
    #while length > 1:
        #outfile.write(block * length + '\n')
        #length = length - 1
    #outfile.write(block * length)
    
f = open('triangle.txt', 'w')
write_ascii_triangle(f, '@', 4)
f.close()
