def fib(n): # 定义到n的斐波那契数列 a, b = 0, 1 while b < n: print(b, ',', end="") a, b = b, a + b print() fib(100) def fib1(n): # 返回到n的斐波那契数列 result = [1, ] a, b = 0, 1 while b < n: a, b = b, a+b result.append(b) return result print(fib1(100))
def fib(n): # 定义到n的斐波那契数列 a, b = 0, 1 while b < n: print(b, ',', end="") a, b = b, a + b print() fib(100) def fib1(n): # 返回到n的斐波那契数列 result = [1, ] a, b = 0, 1 while b < n: a, b = b, a+b result.append(b) return result print(fib1(100))