#! /usr/bin/python3
# -*- coding:utf-8 -*-
def fibonacci():
'''输出斐波那契数列
'''
n = int(input('请输入需要输出的项数:'))
x = 0
y = 1
for _ in range(n):
print(y)
x, y = y, x+y
fibonacci()
运行结果:
// js版本
function fibnacci(n) {
let x = 0;
let y = 1;
for (let i=0; i<n; i++) {
console.log(y);
let tmp = x;
x = y;
y = tmp + y;
}
}
参考文献:
- https://github.com/jackfrued/Python-100-Days