Code:-
num
= int(input("Enter the number of D pattern:"))
string
= ""
def
D_Pattern(string, n):
for i in range(0, n):
for j in range(0, n):
if (j == 1 or ((i == 0 or i == n-1)
and
(j > 1 and j < n-2)) or (j
== n-2 and i != 0 and i != n-1)):
string = string +
"*"
else:
string = string + " "
string = string + "\n"
return(string)
print(D_Pattern(string,
num))
Output:-
No comments:
Post a Comment