Answer to Question #183254 in Python for Omkar

Question #183254

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

* * * * *

* * * *

* * *

* *

*

* *

* * *

* * * *

* * * * *




1
Expert's answer
2021-04-20T05:31:58-0400
# Request user for value of N and convert it to int
print("Enter the value of N to print the sandglass pattern: ")
N = int(input())
for x in range(N):
    for y in range(x):
        print(' ', end='')
    for y in range(N - x):
        print('*', end=' ')
    print()

for x in range(1, N):
    for y in range(N - x - 1):
        print(' ', end='')
    for y in range(x + 1):
        print('*', end=' ')
    print()

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