top of page

Write a Program to Create Empty Star Pattern in Python



Code:

n = int(input('Enter the number of rows:'))
i = 1
while i <= n:
    j = n
    while j > i:
        # display space
        print(' ', end= ' ')
        j -= 1
    print('* ', end= ' ')
    k = 1
    while k < 2 * (i - 1):
        print(' ', end= ' ')
        k += 1
    if i == 1:
        print()
    else:
        print('* ')
    i += 1

i = n - 1
while i >= 1:
    j = n
    while j > i:
        print(' ', end= ' ')
        j -= 1
    print('* ', end= ' ')
    k = 1
    while k < 2 * (i - 1):
        print(' ', end= ' ')
        k += 1
    if i == 1:
        print( )
    else:
        print('*')
    i -= 1

Output:




The Tech Platform

0 comments

Recent Posts

See All

Comments


bottom of page