BEstyle 2022. 11. 27. 00:28

DESCRIPTION:

Create a function that returns a christmas tree of the correct height.

For example:

height = 5 should return:

    *    
   ***   
  *****  
 ******* 
*********

Height passed is always an integer between 0 and 100.

Use \n for newlines between each line.

Pad with spaces so each line is the same length. The last line having only stars, no spaces.


def christmas_tree(height):
    if height==0:
        return ""
    alist=[]
    lmax=height-1
    for i in range(height):
        temp=""
        for j in range(height-1-i):
            temp+=" "
        while len(temp)!=lmax:
            temp+="*"
        alist.append(temp + "*" + temp[::-1])
    return ("\n".join(alist))