defxmas_tree(height):rows=[]# if height is 5, we count from 1 to 5
forrinrange(1,height+1):# append spaces and then *'s:
# - number of spaces: directly inverse to row depth
# - number of *'s: twice the row depth minus one
# (to make an odd total so the center is a '*')
rows.append(' '*(height-r)+'*'*(r*2-1))return'\n'.join(rows)
In Python:
Demo: