We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
for i in range(1, n + 1):
# build ascending and descending numbers
line = list(range(1, i + 1)) + list(range(i - 1, 0, -1))
pyramid.append(''.join(map(str, line))) # we convert numbers to strings here once
single print statement
print(*pyramid, sep='\n')
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Triangle Quest 2
You are viewing a single comment's thread. Return to all comments →
n = int(input()) pyramid = []
for i in range(1, n + 1): # build ascending and descending numbers line = list(range(1, i + 1)) + list(range(i - 1, 0, -1)) pyramid.append(''.join(map(str, line))) # we convert numbers to strings here once
single print statement
print(*pyramid, sep='\n')