Visualizing Fibonacci Sequence with Turtle Graphics
Description
This Python code uses the Turtle graphics library to visually represent the Fibonacci sequence. Each square's side length corresponds to a Fibonacci number, creating a visually appealing spiral.
Code Snippet
import turtle
def fibonacci_spiral(n):
a, b = 0, 1
turtle.speed(0) # Set speed to fastest
for _ in range(n):
turtle.forward(b)
turtle.left(90)
a, b = b, a + b
# Get number of iterations from user
n = int(input("Enter the number of Fibonacci numbers to visualize: "))
fibonacci_spiral(n)
turtle.done()