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
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)
Comments
Leave a comment