python输出费波纳茨数列
时间: 2023-05-23 09:01:37 浏览: 68
可以使用以下代码输出费波纳茨数列:
```python
def fibonacci(n):
if n <= 1:
return n
else:
return (fibonacci(n-1) + fibonacci(n-2))
num_terms = int(input("请输入要输出的费波纳茨数列的项数:"))
if num_terms <= 0:
print("输入错误,请输入一个正整数!")
else:
print("费波纳茨数列:")
for i in range(num_terms):
print(fibonacci(i), end=" ")
```
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)