Skip to content

Instantly share code, notes, and snippets.

@cedrickvstheworld
Created July 8, 2019 09:27
Show Gist options
  • Save cedrickvstheworld/aaebee0c34a4dbb764f2b6ec60b4420c to your computer and use it in GitHub Desktop.
Save cedrickvstheworld/aaebee0c34a4dbb764f2b6ec60b4420c to your computer and use it in GitHub Desktop.
param = int(input('Enter a number: '))
line_length = (param * 2) - 1
for i in range(param + 1)[::-1]:
multiplier = ((i * 2) - 1)
center_string = str(i) * multiplier
if multiplier < line_length:
sides = []
for ii in range(i + 1, param + 1):
sides.append(str(ii))
if i != 0:
print('%s%s%s' % (''.join(sides[::-1]), center_string, ''.join(sides)))
else:
for ix in range(2, param + 1):
multiplier = ((ix * 2) - 1)
center_string = str(ix) * multiplier
if multiplier < line_length:
sides = []
for ii in range(ix + 1, param + 1):
sides.append(str(ii))
print('%s%s%s' % (''.join(sides[::-1]), center_string, ''.join(sides)))
else:
print(center_string)
else:
print(center_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment