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))
'알고리즘 문제 > CodeWar' 카테고리의 다른 글
Reducing by steps (0) | 2022.11.28 |
---|---|
Land perimeter (0) | 2022.11.27 |
Lowest product of 4 consecutive numbers (0) | 2022.11.27 |
Most Frequent Weekdays (0) | 2022.11.27 |
Message Validator (0) | 2022.11.27 |