Answer to Question #223542 in Python for Anand

Question #223542

Digit 9

You are given

N as input. Write a program to print the pattern of 2*N - 1 rows using an asterisk(*) as shown below.Note: There is a space after each asterisk * character.Input

The first line of input is an integer

N.Explanation

In the given example,

N = 4.So, the output should be

* * * *
*     *
*     *
* * * *
      *
      *
* * * *



Sample Input 1

4

Sample Output 1

* * * *
*     *
*     *
* * * *
      *
      *
* * * 

Sample Input 2

5

Sample Output 2


* * * * * 
*       *
*       *
*       *
* * * * * 
        *
        *
        *
* * * * *




1
Expert's answer
2021-08-05T17:51:29-0400
N = int(input())
first_line = '*' * N
first_line = ' '.join(first_line)
nine = first_line

for i in range(N - 2):
    nine += '\n' + '*' + (' ' * (2*N - 3)) + '*'
nine += '\n' + first_line
for i in range(N - 2):
    nine += '\n' + (' ' * (2*N - 2)) + '*'
nine += '\n' + first_line
print(nine)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS