#P0020. 斐波那契螺旋线(提交代码题)
斐波那契螺旋线(提交代码题)
1. Description
Fibonacci sequence is a sequence as below
1, 1, 2, 3, 5, 8, 13, 21 ...
Starting from the third item,each item equals the sum of previous two items
With Python's turtle library, we plot the Fibonacci sequence to a curve (Fibonacci Spiral), which is very common in the real world

The Fibonacci Spiral looks like this

Each side length of squares, and the radius of arcs are items in Fibonacci sequence 1, 1, 2, 3, 5, 8, 13, 21 ...
Copy the code below, and write your code after TODO
import turtle
# 可以用来整体调整线条的长度
LENGTH = 10
# 产生 Fibonacci 数列
def fibonacci(n):
x, y = 0, 1
for i in range(n):
if x > 0:
yield x
y, x = x, x + y
plt = turtle.Turtle()
plt.speed(50)
for i in fibonacci(10):
# TODO: complete your code here
# print(i)
2. About Turtle
With turtle, we can control a pen to plot in Python. You may use the following pen-control methods in thie question.
plt.pencolor(color), assign the pen color, e.g."blue","red","yellow"plt.forward(x)move forward to plot /plt.backward(x)move backward to plot. Usexto set the length of the lineplt.left(angle)turn left /plt.right(angle)turn right. Useangleto set the angle of the turnplt.circle(radius, angle)plot a circle. Useradiusto set circle radius,and useangleto plot partial90means quarter-circle180means semi-circle360means full-circle
3. Submission
- Finish your code in Lecture Note
- Click the "递交 / Submit" button on the right,paste your code and submit
- You can ignore the error report after submission (because the teacher didn't set auto-rating for this problem)