[Solved] Create a pattern that looks like this in a file with n number of lines


Here:

def make_pattern(file_path, n):
    with open(file_path,'w') as f:
        f.write('\n'.join(['*'*(i+1) if (i+1)%2 else '#'*(i+1) for i in range(n)])) # write each string in the list joined by a newline

make_pattern("t.txt", 5)

Output file (t.txt):

*
##
***
####
*****

solved Create a pattern that looks like this in a file with n number of lines