Answer to Question #233113 in Python for kaavya

Question #233113

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-05T08:24:03-0400
n = int(input())
rows = 2 * n - 1
line = '* ' * n
dline = '* ' + '  ' * (n - 2) + '* '
oline = '  ' * (n - 1) + '* '
for n in range(rows):
    if n == 0:
        print(line)
    elif n < (rows - 1) / 2:
        print(dline)
    elif n == (rows - 1) / 2:
        print(line)
    elif (rows - 1) / 2 < n < (rows - 1):
        print(oline)
    elif n == (rows - 1):
        print(line)

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