from random import randint
ornaments = 'NiXJo%b'
o_dict = {idx:ornament for idx, ornament in enumerate(ornaments)}
def get_ornaments(width:int):
result = []
randmax = len(ornaments) * 2
for _ in range(width):
key = randint(0, randmax)
result.append(o_dict.get(key, '*'))
return ''.join(result)
def get_treebody(height:int):
result = []
for h in range(height + 1):
if h:
result.append(get_ornaments(h * 2))
return result
def adjust_pos(body:list):
width = max(map(len, body))
return ['{0:^{1}}'.format(b, width) for b in body]
def build_tree(height:int):
tree = ['☆', '||']
body = get_treebody(height)
tree[1:1] = body
return '\n'.join(adjust_pos(tree))
for x in range(7):
print(build_tree(x))
ZnJvbSByYW5kb20gaW1wb3J0IHJhbmRpbnQKCm9ybmFtZW50cyA9ICdOaVhKbyViJwpvX2RpY3QgPSB7aWR4Om9ybmFtZW50IGZvciBpZHgsIG9ybmFtZW50IGluIGVudW1lcmF0ZShvcm5hbWVudHMpfQoKZGVmIGdldF9vcm5hbWVudHMod2lkdGg6aW50KToKCXJlc3VsdCA9IFtdCglyYW5kbWF4ID0gbGVuKG9ybmFtZW50cykgKiAyCglmb3IgXyBpbiByYW5nZSh3aWR0aCk6CgkJa2V5ID0gcmFuZGludCgwLCByYW5kbWF4KQoJCXJlc3VsdC5hcHBlbmQob19kaWN0LmdldChrZXksICcqJykpCglyZXR1cm4gJycuam9pbihyZXN1bHQpCgpkZWYgZ2V0X3RyZWVib2R5KGhlaWdodDppbnQpOgoJcmVzdWx0ID0gW10KCWZvciBoIGluIHJhbmdlKGhlaWdodCArIDEpOgoJCWlmIGg6CgkJCXJlc3VsdC5hcHBlbmQoZ2V0X29ybmFtZW50cyhoICogMikpCglyZXR1cm4gcmVzdWx0CgpkZWYgYWRqdXN0X3Bvcyhib2R5Omxpc3QpOgoJd2lkdGggPSBtYXgobWFwKGxlbiwgYm9keSkpCglyZXR1cm4gWyd7MDpeezF9fScuZm9ybWF0KGIsIHdpZHRoKSBmb3IgYiBpbiBib2R5XQoKZGVmIGJ1aWxkX3RyZWUoaGVpZ2h0OmludCk6Cgl0cmVlID0gWyfimIYnLCAnfHwnXQoJYm9keSA9IGdldF90cmVlYm9keShoZWlnaHQpCgl0cmVlWzE6MV0gPSBib2R5CglyZXR1cm4gJ1xuJy5qb2luKGFkanVzdF9wb3ModHJlZSkpCgpmb3IgeCBpbiByYW5nZSg3KToKCXByaW50KGJ1aWxkX3RyZWUoeCkpCg==