Created
September 3, 2019 11:54
-
-
Save atul-chaudhary/c8ef008ee2f4b05fda0b98ca17e700b1 to your computer and use it in GitHub Desktop.
HOTS: pattern program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please ignore the red boxes on the pattern