Skip to content

Commit acd962b

Browse files
souravs17031999cclauss
authored andcommitted
adding program to print diamond pattern (TheAlgorithms#1338)
* adding program to print diamond pattern Written a program to print diamond pattern with stars in python 3.7 * update - changing strings to r strings
1 parent e0158c2 commit acd962b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

other/magicdiamondpattern.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Python program for generating diamond pattern in python 3.7+
2+
3+
# Function to print upper half of diamond (pyramid)
4+
def floyd(n):
5+
'''
6+
Parameters:
7+
n : size of pattern
8+
'''
9+
for i in range(0, n):
10+
for j in range(0, n-i-1): # printing spaces
11+
print(" ", end = "")
12+
for k in range(0, i + 1): # printing stars
13+
print("* ", end = "")
14+
print()
15+
16+
17+
# Function to print lower half of diamond (pyramid)
18+
def reverse_floyd(n):
19+
'''
20+
Parameters:
21+
n : size of pattern
22+
'''
23+
for i in range(n, 0, -1):
24+
for j in range(i, 0, -1): # printing stars
25+
print("* ", end = "")
26+
print()
27+
for k in range(n-i+1, 0, -1): # printing spaces
28+
print(" ", end = "")
29+
30+
# Function to print complete diamond pattern of "*"
31+
def pretty_print(n):
32+
'''
33+
Parameters:
34+
n : size of pattern
35+
'''
36+
if n <= 0:
37+
print(" ... .... nothing printing :(")
38+
return
39+
floyd(n) # upper half
40+
reverse_floyd(n) # lower half
41+
42+
43+
if __name__ == "__main__":
44+
print(r"| /\ | |- | |- |--| |\ /| |-")
45+
print(r"|/ \| |- |_ |_ |__| | \/ | |_")
46+
K = 1
47+
while(K):
48+
user_number = int(input("enter the number and , and see the magic : "))
49+
print()
50+
pretty_print(user_number)
51+
K = int(input("press 0 to exit... and 1 to continue..."))
52+
53+
print("Good Bye...")

0 commit comments

Comments
 (0)