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
* * * * *
* *
* *
* *
* * * * *
*
*
*
* * * * *
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)
Comments
Leave a comment