Designer Door Mat

  • + 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)))