如何用python画一个圣诞树呢?
一、最简单的绘制圣诞树
代码也特别简单:
# 最简单的绘制圣诞树
height = 5 # 树的高度
stars = 1 # 树的雪花数,初始为1
for i in range(height): # 以树的高度作为循坏次数
print(('' * (height - i)) + ('*' * stars))
stars += 2
print((''*height)+'|') # 输出树干
运行结果:

二、使用turtle绘制简单圣诞树
# 导入turtle库
import turtle
# 设置屏幕大小
screen = turtle.Screen()
screen.setup(375, 700)
# 获取画笔并设置一些属性:圆形、红色、快
circle = turtle.Turtle()
circle.shape('circle')
circle.color('red')
circle.speed('fastest')
circle.up() # 拾起画笔
# 重新获取画笔
square = turtle.Turtle()
# 重新设置画笔属性:四方形、绿色、快
sq