Q. Write program to print the following shapes :

A.

  *   
 * *  
* * *
 * *  
  *  

B.

*
**
***
**
*

C.

  *  
 * *
*   *
 * *
  *  

D.

*   
**  
* *
*  *
* *
**  
*  


You can understand by Watching video :-



Answer =

A:-

for i in range(6):
    for j in range(6):
        if i < 3 :
            if j >= 2 - i and j <= 2 + i :
                if i % 2 == j % 2 :
                    print(" ", end = "")
                else :
                    print("*", end = "")
            else :
                print(" ", end = "")
        else :
            if j <= 8 - i and j >= i - 4 :
                if i % 2 == j % 2 :
                    print(" ", end = "")
                else :
                    print("*", end = "")
            else :
                print(" ", end = "")
    print()

OR

for i in range(1,7):
	if i<4:
    	print((" "*(4-i))+'* '*i)
    else:
    	print(" "*(i-2)+'* '*(6-i))

B:-

for i in range(1,6):
      if i < 4 :
            print("*" * i )
      else :
            print("*" * (6-i))
print()

C:-

for i in range(5):
      for j in range(5):
            if i < 3 :
                  if j == 2 - i or j == 2 + i :
                        print("*" , end="")
                  else :
                        print(" " ,  end = "")
            else :
                  if j == i-2 or j == 6 - i :
                        print("*" , end="")
                  else :
                        print(" " ,  end = "")
      print()

D:-

for i in range(7):
      for j in range(4):
            if i == j or j == 6-i :
                        print("*" , end="")
            else :
                   if j == 0 :
                        print("*" , end = "")
                   else :
                        print(" ",end="")
      print()

10 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. correct code for a is :-

    for i in range(6):
    for j in range(6):
    if i < 3 :
    if j >=2- i and j <= 2+i :
    if i % 2 == j % 2 :
    print(" ",end="")
    else :
    print("*",end="")
    else :
    print(" ",end="")
    else :
    if j <= 8-i and j >= i - 4:
    if i % 2 == j % 2 :
    print(" ",end="")
    else :
    print("*",end="")
    else :
    print(" ",end="")
    print()

    ReplyDelete
  2. for i in range(6):
    for j in range(6):
    if i < 3 :
    if j >=2- i and j <= 2+i :
    if i % 2 == j % 2 :
    print(" ",end="")
    else :
    print("*",end="")
    else :
    print(" ",end="")
    else :
    if j <= 8-i and j >= i - 4:
    if i % 2 == j % 2 :
    print(" ",end="")
    else :
    print("*",end="")
    else :
    print(" ",end="")
    print()

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. for i in range(1,7):
    if i<4:
    print((" "*(4-i))+'* '*i)
    else:
    print(" "*(i-2)+'* '*(6-i))


    #Try this...It works
    #kamaliegams@yahoo.com

    ReplyDelete
  5. HAVE A NICE DAY

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post