Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

diamond shape in python

def p(n):
    for i in range(n):
        print(" "*(n-i-1),end="")
        print("* "*(i+1))
        
    for j in range(n-1, 0, -1):
        print(" "*(n-j),end="")
        print("* "*(j))

star_num = int(input("Enter a number that shows diameters of your diamond shape: "))
print(p(star_num))
Comment

python code for create diamond shape with integer

n = 9
print("Pattern 1")
for a1 in range(1, (n+1)//2 + 1): #from row 1 to 5
    for a2 in range((n+1)//2 - a1):
        print(" ", end = "")
    for a3 in range((a1*2)-1):
        print("*", end = "")
    print()

for a1 in range((n+1)//2 + 1, n + 1): #from row 6 to 9
    for a2 in range(a1 - (n+1)//2):
        print(" ", end = "")
    for a3 in range((n+1 - a1)*2 - 1):
        print("*", end = "")
    print()
Comment

PREVIOUS NEXT
Code Example
Python :: python strftime cheat sheet 
Python :: python check if false in dict 
Python :: how to exit a loop in python 
Python :: pearsons correlation calculation 
Python :: views.py 
Python :: python invert colormap 
Python :: dataclass in python 
Python :: hierarchy dendrogram 
Python :: dimension of an indez pandas 
Python :: python write a line to a file 
Python :: insert function in list 
Python :: best python books python 3 
Python :: combine picture and audio python 
Python :: Python Tkinter MenuButton Widget 
Python :: gcd python 
Python :: functools.cached_property objects in python 
Python :: how to declare a lambda in python 
Python :: python repr vs str 
Python :: python trace table 
Python :: palindrom python rekursiv 
Python :: how to while true python 
Python :: how to do input python 
Python :: delete plotted text in python 
Python :: dictionary from two list 
Python :: tkinter radio button default selection 
Python :: python string lenght 
Python :: swapping upper case and lower case string python 
Python :: find index of value in list python 
Python :: python list with several same values 
Python :: python reverse dictionary 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =