

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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------------------- ---.|..|..|..|..|..|..|..|..|..|..|..|..|.--- ------.|..|..|..|..|..|..|..|..|..|..|.------ ---------.|..|..|..|..|..|..|..|..|.--------- ------------.|..|..|..|..|..|..|.------------ ---------------.|..|..|..|..|.--------------- ------------------.|..|..|.------------------ ---------------------.|.---------------------
- Related Questions & Answers
- Python program to print Possible Words using given characters
- C program to print characters without using format specifiers
- Ways to print escape characters in python
- Revolving Door in C++
- How to declare OpenCV Mat object using Java?
- How to display OpenCV Mat object using JavaFX?
- How to display OpenCV Mat object using Swings?
- Python program to print rangoli pattern using alphabets
- Program to replace all digits with characters using Python
- Program to design parking system in Python
- C program to print characters and strings in different formats.
- How to print duplicate characters in a String using C#?
- Program to print its script name as output using Python
- How to convert OpenCV Mat object to BufferedImage object using Java?
- Program to print maximum number of characters by copy pasting in n steps in Python?
Advertisements