python动态圣诞树烟花
时间: 2024-01-02 08:22:14 浏览: 70
以下是使用Python绘制动态圣诞树和烟花的代码示例:
```python
import time
def draw_tree():
tree = [
" * ",
" *** ",
" ***** ",
" ******* ",
" ********* ",
" *********** ",
" *** "
]
for i in range(len(tree)):
print(" "*(len(tree)-i-1) + tree[i] + " "*(len(tree)-i-1))
print(" "*(len(tree)-2) + "|||" + " "*(len(tree)-2))
def draw_fireworks():
fireworks = [
" * ",
" *** ",
" ***** ",
"*******",
" ***** ",
" *** ",
" * "
]
for i in range(len(fireworks)):
print(" "*(len(fireworks)-i-1) + fireworks[i] + " "*(len(fireworks)-i-1))
def draw_christmas_tree():
while True:
draw_tree()
time.sleep(1)
print("\033c")
draw_fireworks()
time.sleep(1)
print("\033c")
draw_christmas_tree()
```
这段代码会先绘制一个圣诞树,然后清空屏幕,接着绘制烟花,再次清空屏幕,如此循环。你可以运行这段代码,观察动态效果。
阅读全文