Designer Door Mat in Python - HackerRank Solution
Problem
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 N X M. (N is an odd natural number, and M is 3 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 N and M.
Output Format
Output the design pattern.
Sample Input
9 27
Sample Output
------------.|.------------ ---------.|..|..|.--------- ------.|..|..|..|..|.------ ---.|..|..|..|..|..|..|.--- ----------WELCOME---------- ---.|..|..|..|..|..|..|.--- ------.|..|..|..|..|.------ ---------.|..|..|.--------- ------------.|.------------
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | def Pattern(rows, columns): width = columns for i in range (0, int (rows / 2)): pattern = ".|." * ((2 * i) + 1) print (pattern.center (width, '-')) print ("WELCOME".center (width, '-')) i = int (rows / 2) while i > 0: pattern = ".|." * ((2 * i) - 1) print (pattern.center (width, '-')) i = i-1 return rows,columns =map(int,input().split()) Pattern(rows, columns) |