Designer Door Mat

  • + 0 comments

    First solution I submitted was:

        N, M = map(int,input().split())
        for i in range(1,N,2):
            print(('.|.'*i).center(M,'-'))
        print('Welcome'.center(M,'-'))
        for i in range(N-2,0,-2):
            print(('.|.'*i).center(M,'-'))
    

    Then I used list comprehension and my second solution was:

        N, M = map(int,input().split())
        pattern = [('.|.'*i).center(M,'-') for i in range(1,N,2)]
        print('\n'.join(pattern),'\n'+'WELCOME'.center(M,'-'),'\n'+'\n'.join(pattern[::-1]))
    

    Almost identical to your solution but the print was a mess. I saw your comment here and stole that print statement (I don't know why I didn't think of creating one big list then using join to print it effectively, but I have learnt now.)