Skip to content

Instantly share code, notes, and snippets.

@atul-chaudhary
Created September 3, 2019 11:54
Show Gist options
  • Save atul-chaudhary/c8ef008ee2f4b05fda0b98ca17e700b1 to your computer and use it in GitHub Desktop.
Save atul-chaudhary/c8ef008ee2f4b05fda0b98ca17e700b1 to your computer and use it in GitHub Desktop.
HOTS: pattern program
#for n==9
* * *
* *** *
* ***** *
* ******* *
*---------*********---------*
* ******* *
* ***** *
* *** *
* * *
#for n==5
* * *
* *** *
*-----*****-----*
* *** *
* * *
#here is the program
import math
n = int(input())
x = n
l1 = n + math.ceil(n/2)-1
l2 = n + math.ceil(n/2)-1
for i in range(1, x + 1, 2):
print('*', end='')
if(i==n):
for _ in range(n):
print('-',end='')
else:
for _ in range(l1):
print(end=' ')
l1-=1
for j in range(i):
print('*', end='')
if (i == n):
for _ in range(n):
print('-', end='')
else:
for _ in range(l2):
print(end=' ')
l2 -= 1
print('*',end='')
print()
y=n-2
l3=n+1
l4=n+1
for i in range(y,0,-2):
print('*',end='')
for _ in range(l3):
print(end=' ')
l3+=1
for j in range(i):
print('*',end='')
for _ in range(l4):
print(end=' ')
l4 += 1
print('*',end='')
print()
@atul-chaudhary
Copy link
Author

Please ignore the red boxes on the pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment