Python program to print design door mat texture using characters


Suppose we have two numbers n and m, m will be multiple of n. We have to draw a door mat pattern with a word say "WELCOME" in the middle. The mat size will be n x m. We have to make this mat using dots(.), hyphens (-), pipe symbols (|) and the text at middle.

So, if the input is like n = 5 m = 15, then the output will be

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

To solve this, we will follow these steps −

  • for i in range 1 to n-1, increase by 2, do
    • print(integer of ((m-i*3)/2) number of '-', then i number of '.|.' then integer of ((m-i*3)/2) number of '-'
  • print(integer of ((m-7)/2) number of '-' then 'WELCOME' then integer of ((m-7)/2) number of '-')
  • for i in range n-2 to -1, decrease by 2, do
    • print(integer of ((m-i*3)/2) number of '-', then i number of '.|.' then integer of ((m-i*3)/2) number of '-'

Example

Let us see the following implementation to get better understanding

def solve(n, m):
   for i in range(1,n,2):
      print ('-'*int((m-i*3)/2)+'.|.'*i+'-'*int((m-i*3)/2))

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

   for i in range(n-2,-1,-2):
      print ('-'*int((m-i*3)/2)+'.|.'*i+'-'*int((m-i*3)/2))

n = 15
m = 45
solve(n, m)

Input

15,45

Output

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

Updated on: 11-Oct-2021

396 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements