What could be the shortest as well as easiest approach in solving the given pattern? (See the attachment)
Language: Python.
Explain your answer.
Share
What could be the shortest as well as easiest approach in solving the given pattern? (See the attachment)
Language: Python.
Explain your answer.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
[tex]\underline{\underline{\maltese\:\:\textbf{\textsf{Question}}}}[/tex]
[tex]\underline{\underline{\maltese\:\:\textbf{\textsf{Conditions}}}}[/tex]
[tex]\underline{\underline{\maltese\:\:\textbf{\textsf{Algorithm}}}}[/tex]
[tex]\tt{1.}[/tex] Read input(n).
[tex]\tt{2.}[/tex] find spaces using formula : 2*n-2
[tex]\tt{3.}[/tex] for i in range(0, n), do:
[tex]\tt{4.}[/tex]str=c+' '+str+' '+c
[tex]\tt{5.}[/tex] spaces-= 2
[tex]\underline{\underline{\maltese\:\:\textbf{\textsf{Required Program}}}}[/tex]
n = int(input("Enter the number of rows:"))
spaces = 2 * n - 2
str = 'A'
for i in range(n):
print("[Program finished]")
[tex]\underline{\underline{\maltese\:\:\textbf{\textsf{Out Put}}}}[/tex]
n=int(input("Enter the number of rows: "))
x, y=65,1
for i in range(1,n+1):
for j in range(n-i):
print(" ",end="")
for k in range(2*i-1):
print("%c"%(x),end=" ")
x,y=x+y,-y
print()