Skip to content

Instantly share code, notes, and snippets.

@shamikalashawn
Created February 6, 2017 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamikalashawn/1b2b3c4acfa57a42526c7cbc2823f49c to your computer and use it in GitHub Desktop.
Save shamikalashawn/1b2b3c4acfa57a42526c7cbc2823f49c to your computer and use it in GitHub Desktop.
Using triple nested loops, a number pyramid is returned with periods and numbers printed on each line. The number of periods is determined by what line it is on. Line # - size = number of periods.
def triple_nested_loop(size):
charlist = []
numlist = []
answer = ''
sizelist = range(1,size)
for dot in reversed(sizelist):
charlist.append('.' * dot)
for num in range(1,size+1):
numlist.append(str(num) * num + '\n')
for elem in range(len(numlist)):
if elem == size-1:
answer = answer + str(numlist[elem])
else:
answer = answer + charlist[elem] + str(numlist[elem])
return answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment