Python Online Compiler
Example: Hollow Diamond Pattern in Python using for loop of Stars
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# Hollow Diamond Pattern in Python using for loop of Stars def hollowDiamond(size): pass i, j, diff = 0, 0, 0 diff = int (size / 2) print ("\n-----The hollow diamond pattern is-----\n") # This will print the first half diamond for i in range (1, diff + 1): print (end="\t") for j in range (1, (diff - i) + 1): print (end=" ") if i == 1: print (end="*") else: print (end="*") for j in range (1, (2 *i - 3) + 1): print (end=" ") print (end="*") print (end="\n") # This will print the last half diamond for i in range (diff + 1, size): print (end="\t") for j in range (1, (i - diff) + 1): print (end=" ") if i == size - 1: print (end="*") else: print (end="*") for j in range (1, (2 *(size - i) - 3) + 1): print (end=" ") print (end="*") print (end="\n") print ("-----Enter the size of the hollow diamond, it should be even-----") x = int (input ()) # x - the size of the hollow diamond # Size of the hollow diamond should be even number if x % 2 == 1: x = x + 1 # This will print the hollow diamond pattern hollowDiamond(x)
15
Output
Clear
ADVERTISEMENTS