2020-03-04 12:40:28 +00:00
|
|
|
# Python program for generating diamond pattern in Python 3.7+
|
2019-10-18 22:02:32 +00:00
|
|
|
|
2020-05-22 06:10:11 +00:00
|
|
|
|
2019-10-18 22:02:32 +00:00
|
|
|
# Function to print upper half of diamond (pyramid)
|
|
|
|
def floyd(n):
|
2019-10-22 17:13:48 +00:00
|
|
|
"""
|
2019-11-16 07:05:00 +00:00
|
|
|
Parameters:
|
|
|
|
n : size of pattern
|
2020-09-10 08:31:26 +00:00
|
|
|
"""
|
2019-10-22 17:13:48 +00:00
|
|
|
for i in range(0, n):
|
|
|
|
for j in range(0, n - i - 1): # printing spaces
|
|
|
|
print(" ", end="")
|
|
|
|
for k in range(0, i + 1): # printing stars
|
|
|
|
print("* ", end="")
|
|
|
|
print()
|
2019-10-18 22:02:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Function to print lower half of diamond (pyramid)
|
|
|
|
def reverse_floyd(n):
|
2019-10-22 17:13:48 +00:00
|
|
|
"""
|
2019-11-16 07:05:00 +00:00
|
|
|
Parameters:
|
|
|
|
n : size of pattern
|
2020-09-10 08:31:26 +00:00
|
|
|
"""
|
2019-10-22 17:13:48 +00:00
|
|
|
for i in range(n, 0, -1):
|
|
|
|
for j in range(i, 0, -1): # printing stars
|
|
|
|
print("* ", end="")
|
|
|
|
print()
|
|
|
|
for k in range(n - i + 1, 0, -1): # printing spaces
|
|
|
|
print(" ", end="")
|
|
|
|
|
2019-10-18 22:02:32 +00:00
|
|
|
|
|
|
|
# Function to print complete diamond pattern of "*"
|
|
|
|
def pretty_print(n):
|
2019-10-22 17:13:48 +00:00
|
|
|
"""
|
2019-11-16 07:05:00 +00:00
|
|
|
Parameters:
|
|
|
|
n : size of pattern
|
2020-09-10 08:31:26 +00:00
|
|
|
"""
|
2019-10-22 17:13:48 +00:00
|
|
|
if n <= 0:
|
|
|
|
print(" ... .... nothing printing :(")
|
|
|
|
return
|
|
|
|
floyd(n) # upper half
|
|
|
|
reverse_floyd(n) # lower half
|
2019-10-18 22:02:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-10-22 17:13:48 +00:00
|
|
|
print(r"| /\ | |- | |- |--| |\ /| |-")
|
|
|
|
print(r"|/ \| |- |_ |_ |__| | \/ | |_")
|
|
|
|
K = 1
|
|
|
|
while K:
|
|
|
|
user_number = int(input("enter the number and , and see the magic : "))
|
|
|
|
print()
|
|
|
|
pretty_print(user_number)
|
|
|
|
K = int(input("press 0 to exit... and 1 to continue..."))
|
|
|
|
|
|
|
|
print("Good Bye...")
|