HOME/Articles/

simple python-example-6 (snippet)

Article Outline

Python example 'python-example-6'

Functions in program:

  • def fib(n):

python-example-6

Python example: python-example-6

#!/usr/bin/python
# -*- coding: UTF-8 -*-

def fib(n):
    a,b = 1,1
    for i in range(n-1):
        a,b = b,a+b
    return a

# 输出了第10个斐波那契数列
print(fib(10))