Answer to Question #243038 in Python for balu

Question #243038

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-09-28T02:41:25-0400
n = int(input())
rows = n*2-1
s = ''
for i in range(rows):
	if i == 0 or i == (rows//2) or i == (rows - 1):
		s += '* ' * n + '\n'
	elif i < (rows//2):
		s += '* ' + '  ' * (n-2) + '* ' + '\n'
	else:
		s += '  ' * (n-1) + '* ' + '\n'
s = s[:-1]
print(s)

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