蓝色圣诞树python
时间: 2023-12-20 14:32:28 浏览: 68
以下是一个用Python绘制蓝色圣诞树的例子:
```python
import turtle
def tree(d, s):
if d <= 0:
return
turtle.forward(s)
turtle.right(120)
tree(d-1, s*0.5)
turtle.right(120)
tree(d-1, s*0.5)
turtle.right(120)
turtle.forward(-s)
def trees():
turtle.up()
turtle.goto(0, -200)
turtle.down()
turtle.color("blue")
turtle.begin_fill()
tree(9, 200)
turtle.end_fill()
turtle.up()
turtle.goto(-50, 50)
turtle.down()
turtle.color("yellow")
turtle.begin_fill()
for _ in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
turtle.speed(0)
trees()
turtle.done()
```
相关问题
python蓝色圣诞树
以下是一个用Python绘制蓝色圣诞树的例子:
```python
import turtle
def tree(d, s):
if d <= 0:
return
turtle.forward(s)
turtle.right(120)
tree(d-1, s*0.5)
turtle.right(120)
tree(d-1, s*0.5)
turtle.right(120)
tree(d-1, s*0.5)
turtle.right(120)
turtle.backward(s)
def trees():
turtle.up()
turtle.goto(0, -200)
turtle.down()
turtle.color("blue")
turtle.begin_fill()
tree(9, 200)
turtle.end_fill()
turtle.up()
turtle.goto(-50, 50)
turtle.down()
turtle.color("yellow")
turtle.begin_fill()
for _ in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
turtle.speed(0)
turtle.bgcolor("black")
trees()
turtle.done()
```
圣诞树 python
以下是一个使用Python绘制圣诞树的示例代码:
```python
def draw_christmas_tree(height):
for i in range(height):
print(' ' * (height - i - 1) + '*' * (2 * i + 1))
print(' ' * (height - 1) + '|')
height = 5
draw_christmas_tree(height)
```
这段代码会输出一个高度为5的圣诞树,如下所示:
```
*
***
*****
*******
*********
|
```
你可以根据需要调整`height`变量的值来改变圣诞树的高度。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)