python斐波那契数列前50
时间: 2023-06-09 21:02:41 浏览: 205
个数字是多少?
斐波那契数列是指从第三个开始,每个数都是前两个数之和的数列。前50个数字如下:0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049.
相关问题
python斐波那契数列前50项
Sure! Python code for generating the first 50 terms of the Fibonacci sequence is:
fibonacci = [0, 1]
for i in range(2, 50):
fibonacci.append(fibonacci[i-1] + fibonacci[i-2])
print(fibonacci)
Hope that helps!
python斐波那契数列前30项
斐波那契数列是指从第三项开始,每一项都是前两项的和,即F(n) = F(n-1) + F(n-2),其中F(1) = 1,F(2) = 1。
Python代码如下:
```python
def fibonacci(n):
if n <= 0:
return "输入有误,需要大于0的整数"
elif n == 1:
return [1]
elif n == 2:
return [1, 1]
else:
fib_list = [1, 1]
for i in range(2, n):
next_fib = fib_list[-1] + fib_list[-2]
fib_list.append(next_fib)
return fib_list
fibonacci_sequence = fibonacci(30)
print(fibonacci_sequence)
```
运行以上代码,可以得到斐波那契数列的前30项:
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040]
阅读全文