Skip to content

Commit 73b2761

Browse files
committed
Add program that draws a diamond
1 parent 3f1d2e2 commit 73b2761

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

diamond.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def draw_diamond(n):
2+
if n % 2 != 0:
3+
k = 1
4+
while k <= n:
5+
print(' '*int((n - k)/2)+'*'*k+' '*int((n - k)/2))
6+
k += 2
7+
8+
j = 1
9+
while (n-2*j) >= 1:
10+
print(' ' *j + '*' * (n-2*j) + ' ' * (j))
11+
j += 1
12+
else:
13+
print('Not an odd number. Can\'t draw a diamond :(')
14+
15+
16+
n = int(input('Enter an odd number: '))
17+
draw_diamond(n)

0 commit comments

Comments
 (0)