624
In this article we display a sandglass pattern using python
Code
rows = int(input("Enter amount of Rows = ")) print("====Pattern====") for i in range(0, rows): for j in range(0, i): print(end = ' ') for k in range(i, rows): print('*', end = ' ') print() for i in range(rows - 1, -1, -1): for j in range(0, i): print(end = ' ') for k in range(i, rows): print('*', end = ' ') print()
When you run this you would see something like this
Alternative
def drawSandglass(rows, ch): for i in range(0, rows): for j in range(0, i): print(end = ' ') for k in range(i, rows): print('%c' %ch, end = ' ') print() for i in range(rows - 1, -1, -1): for j in range(0, i): print(end = ' ') for k in range(i, rows): print('%c' %ch, end = ' ') print() rows = int(input("Enter amount of Rows = ")) char = input("Symbol to use = " ) print("====Pattern====") drawSandglass(rows, char)