Python Program to Print 8 Star Pattern

Write a Python program to print 8 star pattern using for loop.

rows = int(input("Enter 8 Star Pattern Rows = "))

print("====The 8 Star Pattern====")

for i in range(1, rows * 2):
    if i == 1 or i == rows or i == rows * 2 - 1:
        for j in range(1, rows + 1):
            if j == 1 or j == rows:
                print(end = ' ')
            else:
                print('*', end = '')
    else:
        for k in range(1, rows + 1):
            if k == 1 or k == rows:
                print('*', end = '')
            else:
                print(end = ' ')
    print()
Python Program to Print 8 Star Pattern

Python Program to Print 8 Star Pattern using a while loop

rows = int(input("Enter Rows = "))

i = 1

while(i < rows * 2):
    if i == 1 or i == rows or i == rows * 2 - 1:
        j = 1
        while(j <= rows):
            if j == 1 or j == rows:
                print(end = ' ')
            else:
                print('*', end = '')
            j = j + 1
    else:
        k = 1
        while(k <= rows):
            if k == 1 or k == rows:
                print('*', end = '')
            else:
                print(end = ' ')
            k = k + 1
    print()
    i = i + 1
Enter Rows = 8

 ****** 
*      *
*      *
*      *
*      *
*      *
*      *
 ****** 
*      *
*      *
*      *
*      *
*      *
*      *
 ****** 

In this Python example, the star8Pattern function allows rows and characters and prints the 8 digit patterns of a given character.

def star8Pattern(rows, ch):
    for i in range(1, rows * 2):
        if i == 1 or i == rows or i == rows * 2 - 1:
            for j in range(1, rows + 1):
                if j == 1 or j == rows:
                    print(end = ' ')
                else:
                    print('%c' %ch, end = '')
        else:
            for k in range(1, rows + 1):
                if k == 1 or k == rows:
                    print('%c' %ch, end = '')
                else:
                    print(end = ' ')
        print()

rows = int(input("Enter Rows = "))
ch = input("Symbol to use = " )


star8Pattern(rows, ch)
Enter Rows = 10
Symbol to use = $

 $$$$$$$$ 
$        $
$        $
$        $
$        $
$        $
$        $
$        $
$        $
 $$$$$$$$ 
$        $
$        $
$        $
$        $
$        $
$        $
$        $
$        $
 $$$$$$$$