Computer Science, asked by anindyaadhikari13, 2 months ago

What could be the shortest as well as easiest approach in solving the given pattern? (See the attachment)

Language: Python.

Explain your answer.​

Attachments:

Answers

Answered by RockingStarPratheek
31

\underline{\underline{\maltese\:\:\textbf{\textsf{Question}}}}

  • What could be the shortest as well as easiest approach in solving the given pattern ? \sf{(R}\mathfrak{efer\:\: in\:\: Attachment - 1)}

\underline{\underline{\maltese\:\:\textbf{\textsf{Conditions}}}}

  • Need Shortest and Easiest Approach in Solving the Given Pattern
  • Language to be used : Python

\underline{\underline{\maltese\:\:\textbf{\textsf{Algorithm}}}}

\tt{1.} Read input(n).  

\tt{2.} find spaces using formula : 2*n-2

\tt{3.} for i in range(0, n), do:  

  •    print spaces and the string.
  •    If i%2
  •        then c = A
  •        else c = B

\tt{4.}str=c+' '+str+' '+c

\tt{5.} spaces-= 2

\underline{\underline{\maltese\:\:\textbf{\textsf{Required Program}}}}

n = int(input("Enter the number of rows:"))

spaces = 2 * n - 2

str = 'A'

for i in range(n):

  • print(spaces*' '+str)
  • c = 'A' if i % 2 else 'B'
  • str = c+' '+str+' '+c
  • spaces-= 2

print("[Program finished]")

\underline{\underline{\maltese\:\:\textbf{\textsf{Out Put}}}}

  • For the Output of the above Program, \sf{(R}\mathfrak{efer\:\: in\:\: Attachment - 2)}      
Attachments:

EliteSoul: Nice
Anonymous: Superb!
Blossomfairy: Awesome :)
MisterIncredible: Good
mddilshad11ab: Perfect¶
Anonymous: Great :)
Answered by thapaavinitika6765
5

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()

Similar questions