马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import turtle
def draw_branch(branch_length):
"""
绘制分形树
"""
if branch_length > 5:
# 绘制右侧的树枝
turtle.forward(branch_length)
print('向前', branch_length)
turtle.right(20)
print('右转', 20)
draw_branch(branch_length - 15)
# 绘制左侧树枝
turtle.left(40)
print('左转', 40)
draw_branch(branch_length - 15)
# 返回之前的树枝上
turtle.right(20)
print('右转', 20)
turtle.backward(branch_length)
print('向后', branch_length)
def main():
"""
主函数
"""
turtle.left(90)
turtle.penup()
turtle.backward(500)
turtle.pendown()
draw_branch(100)
turtle.exitonclick()
if __name__ == '__main__':
main()
这是报错:
in main turtle.left(90) AttributeError: module 'turtle' has no attribute 'left'
|