Designer Door Mat

Sort by

recency

|

1828 Discussions

|

  • + 0 comments

    N, M = map(int, input().split())

    for i in range(N // 2): pattern = ".|." * (2 * i + 1) # repeat .|. (odd times) print(pattern.center(M, "-")) # center with '-' print("WELCOME".center(M, "-")) for i in range(N // 2 - 1, -1, -1): # reverse loop pattern = ".|." * (2 * i + 1) print(pattern.center(M, "-"))

  • + 0 comments

    One of Python’s main focuses is to improve readability; it’s important to remember, when writing code, that others will need to read it. I believe this code makes it easy to understand what is happening. In addition, I made sure not to recalculate anything unnecessary: since there are two mirrored patterns, the top and bottom are the same. Therefore, it’s unnecessary to perform calculations for each one—calculating it once and then iterating over it in reverse is enough.

    def pattern_lines(x: int, y: int) -> list[str]:
        return [(".|." * (2 * i + 1)).center(y, "-") for i in range(x//2)]
        
    x,y = map(int, input().split(" "))
    lines = pattern_lines(x,y)
    
    print("\n".join(lines))
    print(("WELCOME").center(y,"-"))
    print("\n".join(reversed(lines)))
    
  • + 0 comments

    design = ".|." greeting = "WELCOME"

    [m,n] = list(map(int, input().split()))

    for i in range(m//2): print((design*i).rjust(n//2 - 1, '-') + design + (design*i).ljust(n//2 - 1, '-'))

    print(greeting.center(n, '-'))

    for i in range(m//2 - 1, -1, -1): print((design*i).rjust(n//2 - 1, '-') + design + (design*i).ljust(n//2 - 1, '-'))

  • + 0 comments

    N, M = map(int,input().split()) for i in range(N): if i < (N//2): print(('.|.'*((i*2)+1)).center(M,'-')) if i == (N//2): print("WELCOME".center(M,'-')) elif i > (N//2): print(('.|.'*((N-i-1)*2+1)).center(M,'-'))

  • + 0 comments
    ``
    def mod(x):
        if x<0:
            return -x
        else:
            return x
    
    for i in range(rows, -rows-1, -1):
        if i == 0:
            print(int((M-7)/2)*'-' + 'WELCOME' + int((M-7)/2)*'-')
        else:
            print(mod(i)*'---' + (N-2*mod(i))*pin + 
                  mod(i)*'---')