黄金分割数列python
时间: 2023-10-19 13:08:54 浏览: 140
python中黄金分割法实现方法
黄金分割数列是一种特殊的数列,它的每个元素都是前两个元素的和。即数列的第n个元素等于第n-1个元素与第n-2个元素的和。首两个元素通常是1和1。以下是一个用Python编写的黄金分割数列的示例代码:
```python
def golden_ratio_sequence(n):
sequence = [1, 1]
for i in range(2, n):
next_number = sequence[i-1] + sequence[i-2]
sequence.append(next_number)
return sequence
n = 10 # 你可以修改n来指定数列的长度
sequence = golden_ratio_sequence(n)
print(sequence)
```
输出结果为:[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
阅读全文