We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Strings
- Designer Door Mat
- Discussions
Designer Door Mat
Designer Door Mat
Sort by
recency
|
1828 Discussions
|
Please Login in order to post a comment
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, "-"))
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.
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, '-'))
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,'-'))