Designer Door Mat

  • + 0 comments
    def is_valid_input(height: int, width: int) -> bool:
        return (
            isinstance(height, int)
            and isinstance(width, int)
            and height % 2 == 1
            and width == height * 3
            and 5 < height < 101
        )
    
    
    def design_doormat(height: int, width: int) -> list[str]:
        if not is_valid_input(height, width):
            raise ValueError("Invalid input: N must be odd, M must be 3*N")
    
        lines = []
    
        # Top
        for i in range(1, height, 2):
            pattern = ".|." * i
            lines.append(pattern.center(width, "-"))
    
        # Center
        lines.append("WELCOME".center(width, "-"))
    
        # Bottom
        for i in range(height - 2, 0, -2):
            pattern = ".|." * i
            lines.append(pattern.center(width, "-"))
    
        return lines
    
    
    if __name__ == "__main__":
        n, m = map(int, input().split())
        for line in design_doormat(n, m):
            print(line)