Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

菜鳥教程練習:Python一百例

# -*- coding: utf-8 -*-
# 1 1 2 3 5 8 13 21 34 55 89
def Fib(n):
    a, b = 0, 1 # a 是第零項; b 是第一項
    while n:
        a, b = b, a + b
        n -= 1
        print a     #放在迴圈內就會列出所有數值
    #print a         #放在迴圈就只顯示那個最終加成的數值
    # 做第一次之後, a 成為第一項;所以做四次,a 就是第四項
Fib(4)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.