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()
correct code for a is :-
ReplyDeletefor 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()
Thanks for Telling Us : )
Deletefor i in range(6):
ReplyDeletefor 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()
We have improve it : )
DeleteThis comment has been removed by the author.
ReplyDeletefor i in range(1,7):
ReplyDeleteif i<4:
print((" "*(4-i))+'* '*i)
else:
print(" "*(i-2)+'* '*(6-i))
#Try this...It works
#kamaliegams@yahoo.com
Ok. Your answer also written in Answer : )
DeleteFREE IS SUPER
ReplyDeleteHAVE A NICE DAY
ReplyDeleteThank you : )
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )