Given an integer N, write a program to print the sandglass star pattern, similar to the pattern shown below.
* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
Input
The input will be a single line containing a positive integer (N).
Output
The output should contain the asterisk(*) characters in the sandglass star pattern.
Note: There is a space after each asterisk(*) character.
Explanation
For example, if the given number is 5, the pattern should contain 9 rows and 9 columns as shown below.
* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
Sample Input 1
5
Sample Output 1
* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
Sample Input 2
3
Sample Output 2
* * *
* *
*
* *
* * *
N = int(input())
for i in range(N):
for j in range(i):
print(' ', end='')
for j in range(N-i):
print('*', end=' ')
print()
for i in range(1, N):
for j in range(N-i-1):
print(' ', end='')
for j in range(i+1):
print('*', end=' ')
print()
Comments
Leave a comment