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
31
- What could be the shortest as well as easiest approach in solving the given pattern ?
- Need Shortest and Easiest Approach in Solving the Given Pattern
- Language to be used : Python
Read input(n).
find spaces using formula : 2*n-2
for i in range(0, n), do:
- print spaces and the string.
- If i%2
- then c = A
- else c = B
str=c+' '+str+' '+c
spaces-= 2
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]")
- For the Output of the above Program,
Attachments:
EliteSoul:
Nice
Answered by
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