题解 | 超级圣诞树

超级圣诞树

https://www.nowcoder.com/practice/470d26c9a73e4e17be8cc45cac843423

n = int(input())
max_width = 5*(2**(n-1))+2**(n-1)-1
level = 3 
line = ['*','* *','* * *']
for i in range(1,n):
    for j in range(level):
        space = 6*(2**(i-1)) -2*j -1 if i >0 else 0
        line.append(line[j]+' '*space+line[j]) 
    level += level
for l in line:
    print(l.center(max_width))
for i in range(n):
    print('*'.center(max_width))
#level 3 3 6 12 24
#n     1 2 3 4 5

全部评论

相关推荐

03-12 15:35
嘉应学院 Python
快说谢谢牛牛精灵:说不定就是下一个寒武纪!
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务