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----------
---.|..|..|..|..|..|..|.---
------.|..|..|..|..|.------
---------.|..|..|.---------
------------.|.------------
Designer Door Mat - Hacker Rank Solution
Python String center() Method
Syntax
str.center(width[, fillchar])
width: Total width of the string.
fillchar: Filler character.
Problem Setter's code:
N,M = map(int,raw_input().split())
for i in xrange(1, N, 2):
print ( str('.|.')*i ).center(M, '-')
print str('WELCOME').center(M, '-')
for i in xrange(N-2, -1, -2):
print ( str('.|.')*i ).center(M, '-')
xrange name is not define -error
ReplyDeleteuse range instead of xrange
Deleteuse range instead of xrange and input instead of raw input
Deleten,m = map(int,input().split())
ReplyDeletepattern = [ ((".|.")*(2*i+1)).center(m,'-') for i in range(n//2) ]
print('\n'.join( pattern + ["WELCOME".center(m,'-')] + pattern[::-1] ))
N,M = map(int,input().split())
ReplyDeletec = ".|."
for i in range(N//2):
print((c*((i*2)+1)).center(M, '-'))
print(('WELCOME'.center(M,'-')))
for j in range(N//2):
print((c*((N-(j*2))-2)).center(M, '-'))
This is the solution I came up with
What's the meaning of
ReplyDelete"if__ name__=="__ main__":" in hackerrank
it represents main class just like void main in java
Delete