def fibonacci(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib_list = fibonacci(n - 1)
fib_list.append(fib_list[-1] + fib_list[-2])
return fib_list
# 测试函数
length = 10 # 想要生成的斐波那契数列长度
result = fibonacci(length)
print("斐波那契数列前", length, "项为:", result)