Created
February 6, 2017 23:34
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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