Answer to Question #320213 in Python for Rajesh

Question #320213

Right Triangle

Given a number N write a program to print a triangular pattern of N lines with the number as shown below

1

121

12321

1234321


1
Expert's answer
2022-03-29T05:19:09-0400
N = int(input())
w = len(str(N))
for i in range(N):
	nums = [" "*(w-len(str(j)))+str(j) for j in range(1,i+2)]
	nums += nums[-2::-1]
	s = " "*(w*(N-i-1)) + "".join(nums)
	print(s)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS