Write a Python Program to Print Mirrored Half Diamond Star Pattern using for loop.
# Python Program to Print Mirrored Half Diamond Star Pattern rows = int(input("Enter Mirrored Half Diamond Pattern Rows = ")) print("Mirrored Half Diamond Star Pattern") for i in range(rows): for j in range(0, rows - i): print(' ', end = '') for k in range(0, i): print('*', end = '') print() for i in range(rows, 0, -1): for j in range(0, rows - i): print(' ', end = '') for k in range(0, i): print('*', end = '') print()
This Python Program prints the Mirrored Half Diamond Star Pattern using a while loop.
# Python Program to Print Mirrored Half Diamond Star Pattern rows = int(input("Enter Mirrored Half Diamond Pattern Rows = ")) print("Mirrored Half Diamond Star Pattern") i = 1 while(i <= rows): j = 1 while(j <= rows - i): print(' ', end = '') j = j + 1 k = 1 while(k <= i): print('*', end = '') k = k + 1 i = i + 1 print() i = rows - 1 while(i > 0): j = 1 while(j <= rows - i): print(' ', end = '') j = j + 1 k = 1 while(k <= i): print('*', end = '') k = k + 1 i = i - 1 print()
Enter Mirrored Half Diamond Pattern Rows = 7
Mirrored Half Diamond Star Pattern
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
>>>
In this Python example, we created a mirroredHalfDiamond function to Print the Mirrored Half Diamond Pattern. It replaces the star in the mirrored half diamond pattern with a given symbol.
# Python Program to Print Mirrored Half Diamond Star Pattern def mirroredHalfDiamond(rows, ch): for i in range(rows): for j in range(0, rows - i): print(' ', end = '') for k in range(0, i): print('%c' %ch, end = '') print() for i in range(rows, 0, -1): for j in range(0, rows - i): print(' ', end = '') for k in range(0, i): print('%c' %ch, end = '') print() rows = int(input("Enter Mirrored Half Diamond Pattern Rows = ")) ch = input("Symbol to use in Mirrored Half Diamond Pattern = ") print("Mirrored Half Diamond Pattern") mirroredHalfDiamond(rows, ch)
Enter Mirrored Half Diamond Pattern Rows = 8
Symbol to use in Mirrored Half Diamond Pattern = #
Mirrored Half Diamond Pattern
#
##
###
####
#####
######
#######
########
#######
######
#####
####
###
##
#
>>>