-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiamond1.py
More file actions
30 lines (30 loc) · 793 Bytes
/
diamond1.py
File metadata and controls
30 lines (30 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#take input from user
rowSize = int(input("enter the number of rows: "))
if rowSize%2==0: #conditions
halfDiamRow = int(rowSize/2)
else:
halfDiamRow = int(rowSize/2)+1
space = halfDiamRow-1
#loop for upper part
for i in range(1, halfDiamRow+1): #loop for rows
for j in range(1, space+1): #loop for columns
print(end=" ")
space = space-1
num = 1
for j in range(2*i-1):
print(end=str(num))
#incerementing number at each column
num = num+1
print()
space = 1
#loop for lower part
for i in range(1, halfDiamRow): #loop for rows
for j in range(1, space+1): #loop for columns
print(end=" ")
space = space+1
num = 1
for j in range(1, 2*(halfDiamRow-i)):
print(end=str(num)) #display result
#incerementing number at each column
num = num+1
print()