What does it take to design a door-mat using Python?

Shivam Dutt Sharma
2 min readApr 3, 2020

--

Mr. Vincent works in a door mat manufacturing company. One day, he designed a new door mat with the following specifications:

  • Mat size must be X. ( is an odd natural number, and is times .)
  • The design should have ‘WELCOME’ written in the center.
  • The design pattern should only use |, . and - characters.

Sample Designs

Size: 7 x 21 
---------.|.---------
------.|..|..|.------
---.|..|..|..|..|.---
-------WELCOME-------
---.|..|..|..|..|.---
------.|..|..|.------
---------.|.---------

Size: 11 x 33
---------------.|.---------------
------------.|..|..|.------------
---------.|..|..|..|..|.---------
------.|..|..|..|..|..|..|.------
---.|..|..|..|..|..|..|..|..|.---
-------------WELCOME-------------
---.|..|..|..|..|..|..|..|..|.---
------.|..|..|..|..|..|..|.------
---------.|..|..|..|..|.---------
------------.|..|..|.------------
---------------.|.---------------

Input Format

A single line containing the space separated values of and .

Constraints

Output Format

Output the design pattern.

Sample Input

9 27

Sample Output

------------.|.------------
---------.|..|..|.---------
------.|..|..|..|..|.------
---.|..|..|..|..|..|..|.---
----------WELCOME----------
---.|..|..|..|..|..|..|.---
------.|..|..|..|..|.------
---------.|..|..|.---------
------------.|.------------

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Let’s dive into the code for it!

# Enter your code here. Read input from STDIN. Print output to STDOUT

if __name__ == ‘__main__’:

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

assert ((5 < N < 101) and (15 < M < 303) and M == 3*N), “N should be greather than 5 and less than 101. M should be greater than 15 and less than 303.”

c1, strn = ‘-’, “.|.”

wel = “WELCOME”

n = N//2

count1 = 1

dec1 = 1

count2 = int((M-6)/3)

#Upper half

for i in range(1, n+1):

print((c1*int((M-(3*dec1))/2) + (strn*count1) + (c1*int((M-(3*dec1))/2))))

count1 += 2

dec1 += 2

#Middle Line

print((c1*int((M-7)/2)) + wel + (c1*int((M-7)/2)))

#Lower half

for i in range(1, n+1):

print((c1*int(i*3)) + (strn*count2) + (c1*int(3*i)))

count2 -= 2

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Shivam Dutt Sharma
Shivam Dutt Sharma

Written by Shivam Dutt Sharma

Data Science . Product Engineering . Tennis . Running

No responses yet

Write a response