Last active
December 25, 2015 11:09
-
-
Save boxmein/6967281 to your computer and use it in GitHub Desktop.
Creates two equal triangles in a hourglass formation-ish
This file contains hidden or 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
# -*- encoding:utf8 -*- | |
def magic(width): | |
lines = [] | |
oldwidth = width | |
# going downwards | |
width += 2 | |
while width-2 > 0: | |
lines.append(str.center("* " * (width-2), oldwidth*2)) | |
width -= 2 | |
# going back up | |
lines = lines + lines[::-1][1:] | |
# done! | |
return lines | |
# for line in magic(15): print(line) | |
# for line in magic(7): print(line) | |
# for line in magic(8): print(line) | |
if __name__ == '__main__': | |
while True: | |
lines = input("Sisesta paaritu arv >> ") | |
try: | |
lines = int(lines) | |
except: | |
print("Intiks castimine ei õnnestunud kahjuks") | |
continue | |
for line in magic(lines): | |
print(line) | |
# programming challenge carl roberti jaoks | |
# make a python function magic so that magic(5) would return | |
# magic(5): | |
# ['* * * * *', | |
# ' * * * ', | |
# ' * ', | |
# ' * * * ', | |
# '* * * * *'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment