Skip to content

Instantly share code, notes, and snippets.

@boxmein
Last active December 25, 2015 11:09
Show Gist options
  • Save boxmein/6967281 to your computer and use it in GitHub Desktop.
Save boxmein/6967281 to your computer and use it in GitHub Desktop.
Creates two equal triangles in a hourglass formation-ish
# -*- 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