Write a Python program to print a Diamond Shape Pattern with *

Tech Programmer
1

   WRITE A PYTHON PROGRAM TO PRINT A DIAMOND SHAPE PATTERN WITH * ?

 

CODE FOR THE ABOVE  PYTHON  PROGRAM :



# Write a python program to print a diamond shape pattern with *.
n = 5
# Upper half
k = round(n/2)*2
for i in range(0n2):
    for j in range(0k+1):
        print(end=" ")
    for j in range(0i+1):
        print("* "end="")
    k = k-2
    print()
# Lower half
k = 1
for i in range(n-10, -2):
    for j in range(0k+2):
        print(end=" ")
    for j in range(0,i-1):
        print("* ",end="")
    k = k+2
    print()


WRITTEN CODE FOR THE ABOVE PROGRAM :


n = 5

# Upper half

k = round(n/2)*2

for i in range(0, n, 2):

    for j in range(0, k+1):

        print(end=" ")

    for j in range(0, i+1):

        print("* ", end="")

    k = k-2

    print()

# Lower half

k = 1

for i in range(n-1, 0, -2):

    for j in range(0, k+2):

        print(end=" ")

    for j in range(0,i-1):

        print("* ",end="")

    k = k+2

    print()


  OUTPUT :




Post a Comment

1Comments
Post a Comment

Featured Highlighted Categories

You'll discover all of the most up-to-date bring innovative here.

Python List theory with List Programs
Get complete python lists theory and list basic and insane programs for your practice.
CBSE SAMPLE PAPERS
Get CBSE sample and question papers of last 7 years with answers to get best practice for your Board Exams
Python String theory and String Programs
Python strings complete theory with illustrations and practice programs for free