Python绘制圣诞树的代码
时间: 2023-12-25 07:30:04 浏览: 80
Python画圣诞树源代码
5星 · 资源好评率100%
以下是用Python绘制圣诞树的代码:
```python
import time
def draw_tree(height):
for i in range(height):
print(' ' * (height - i - 1) + '*' * (2 * i + 1))
print(' ' * (height - 1) + '|')
def draw_star():
print(' *')
print(' ***')
print(' *****')
print('*******')
print(' |')
def draw_hat():
print(' *')
print(' ***')
print(' *****')
print('*******')
print(' ***')
print(' ***')
def draw_christmas_tree(height):
draw_tree(height)
draw_star()
draw_hat()
def animate_christmas_tree(height):
for i in range(height):
draw_tree(i+1)
time.sleep(0.5)
print('\033c', end='') # 清屏
draw_star()
draw_hat()
# 绘制静态圣诞树
draw_christmas_tree(5)
# 绘制动态圣诞树
animate_christmas_tree(5)
```
阅读全文