Designer Door Mat

Sort by

recency

|

1830 Discussions

|

  • + 0 comments

    r,c=map(int,input().split())

    m='-' mc=(c-3)//2 l=l1='.'+'|'+'.'

    for i in range(r//2): print(m*mc+l+m*mc) mc-=3 l=l+l1+l1

    print(m*((c-7)//2)+'WELCOME'+m*((c-7)//2))

    for i in range(r//2): l=l[:len(l)-6] mc+=3 print(m*mc+l+m*mc)

  • + 0 comments
    # using python's .center method:
    height, width = map(int, input().split())
    
    pattern_list: list[str] = []
    
    for i in range(1, height, 2):
        pattern_list.append((".|." * i).center(width, "-"))
    
    print(*pattern_list, sep="\n")
    print("WELCOME".center(width, "-"))
    print(*pattern_list[::-1], sep="\n")
    
    # vs
    
    # calculating patterns manually:
    height, width = map(int, input().split())
    
    pattern_list: list[str] = []
    
    for i in range(1, height, 2):
        dash_length: int = (width - (i * 3)) // 2
        dash_line: str = "-" * dash_length
        line: str = dash_line + (".|." * i) + dash_line
    
        pattern_list.append(line)
    
    welcome_dash_length: int = (width - 7) // 2
    welcome_dash_line: str = "-" * welcome_dash_length
    
    print(*pattern_list, sep="\n")
    print(welcome_dash_line + "WELCOME" + welcome_dash_line)
    print(*pattern_list[::-1], sep="\n")
    
  • + 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, '-'))