fork download
  1. from random import randint
  2.  
  3. ornaments = 'NiXJo%b'
  4. o_dict = {idx:ornament for idx, ornament in enumerate(ornaments)}
  5.  
  6. def get_ornaments(width:int):
  7. result = []
  8. randmax = len(ornaments) * 2
  9. for _ in range(width):
  10. key = randint(0, randmax)
  11. result.append(o_dict.get(key, '*'))
  12. return ''.join(result)
  13.  
  14. def get_treebody(height:int):
  15. result = []
  16. for h in range(height + 1):
  17. if h:
  18. result.append(get_ornaments(h * 2))
  19. return result
  20.  
  21. def adjust_pos(body:list):
  22. width = max(map(len, body))
  23. return ['{0:^{1}}'.format(b, width) for b in body]
  24.  
  25. def build_tree(height:int):
  26. tree = ['☆', '||']
  27. body = get_treebody(height)
  28. tree[1:1] = body
  29. return '\n'.join(adjust_pos(tree))
  30.  
  31. for x in range(7):
  32. print(build_tree(x))
  33.  
Success #stdin #stdout 0.14s 12248KB
stdin
Standard input is empty
stdout
☆ 
||
☆ 
*i
||
 ☆  
 ** 
*No*
 || 
  ☆   
  **  
 %*N* 
***X*i
  ||  
   ☆    
   J%   
  *i**  
 *****J 
J*%N*oJ*
   ||   
    ☆     
    *N    
   o*N*   
  *N*ioX  
 *J*Jii*J 
*Xb%**%**%
    ||    
     ☆      
     N*     
    *N**    
   X%JNX%   
  N***%**b  
 %****J*JJ* 
**N*%Xb*XJJN
     ||