Skip to content

Commit debb59e

Browse files
Merge pull request #37 from anushhka/main
Create diamond shape
2 parents b98e1a0 + 44905ed commit debb59e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

diamond shape

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
rows = int(input("Enter the number of rows: "))
2+
3+
# It is used to print the space
4+
k = 2 * rows - 2
5+
# Outer loop to print number of rows
6+
for i in range(0, rows):
7+
# Inner loop is used to print number of space
8+
for j in range(0, k):
9+
print(end=" ")
10+
# Decrement in k after each iteration
11+
k = k - 1
12+
# This inner loop is used to print stars
13+
for j in range(0, i + 1):
14+
print("* ", end="")
15+
print("")
16+
17+
# Downward triangle Pyramid
18+
# It is used to print the space
19+
k = rows - 2
20+
# Output for downward triangle pyramid
21+
for i in range(rows, -1, -1):
22+
# inner loop will print the spaces
23+
for j in range(k, 0, -1):
24+
print(end=" ")
25+
# Increment in k after each iteration
26+
k = k + 1
27+
# This inner loop will print number of stars
28+
for j in range(0, i + 1):
29+
print("* ", end="")
30+
print("")

0 commit comments

Comments
 (0)