--- title: 16.實作2:費式數列 tags: python基礎語法與應用, 筆記 --- # 費氏數列 0,1,前兩項固定0,1 第三項=前兩項相加 0,1,1,2,3,5,8 除了第1跟第2其他=前2+前1 ``` lasttwo = 0 lastone = 0 times = 0 while times < 10: if times == 0: lasttwo = 0 ans = 0 elif times == 1: lastone = 1 ans = 1 else: ans = lasttwo + lastone lasttwo = lastone lastone = ans print ("第", times + 1, "項:", ans) times = times +1 ``` --- 第 1 項: 0 第 2 項: 1 第 3 項: 1 第 4 項: 2 第 5 項: 3 第 6 項: 5 第 7 項: 8 第 8 項: 13 第 9 項: 21 第 10 項: 34 # END
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up