### 載入中...

相關課程

⇐ Use this menu to view and help create subtitles for this video in many different languages.
You'll probably want to hide YouTube's captions if using these subtitles.

# Exercise - Write a Fibonacci Function : Introduction to the Fibonacci Sequence and a programming challenge

相關課程

選項
分享

0 / 750

- This right here is a picture of Fibonacci.
- One of the most famous mathematicians of all time
- And he was a mathematicians in medieval Italy
- And he is most famous for the Fibonacci numbers
- Fibonacci numbers
- And he didn't discover them, they acturally discovered several centuries before mid India
- But he popularized them, especially in the west
- And Fibonacci numbers are super simple
- The first two are defined as 0 and 1
- And every number after that is the sum of the previous two
- So what I'm constructing right here is really a Fibonacci sequence of numbers
- So the next number in the sequence is gonna be 0 + 1, which is 1.
- Then the next number after that is going to be 1 + 1, which is 2
- And the next number after that, 1 + 2 is 3
- 2 + 3 is 5
- 3 + 5 is 8
- 5 + 8 is 13
- 8 + 13 is 21
- 13 + 21 is 34
- And the Fibonacci numbers, you know especial once you start getting into number theory
- Tons of fancinating things about them
- Probably the coolest thing about them
- is as you add more and more terms through the Fibonacci sequence
- And you take the last two terms that you generated
- You'll see there's no really last two terms you can keep going on forever
- get arbitrarily large Fibonacci numbers
- Say we take these last two terms over here
- 21, 34, we take the ratio of these two
- 21 over 34, this is going to be pretty close to the golden ratio
- and I encourage you to look up the golden ratio on wikipedia and Internet
- you will find all sorts of fascinating mystical things about the golden ratio
- What's cool about the Fibonacci numbers or Fibonacci sequences
- This gives you approximation of the golden ratio
- We get a better even a better approximation if you add another terms for a sequence
- So the next term over here 21 + 34 is 55
- So the ratio of 34 than 55 is even closer
- even closer to the golden ratio
- So one way if you want to compute a really good approximation for the golden ratio
- You can really just get super high Fibonacci numbers just adding the previous 2 terms to get the next one
- and you will get a pretty good approximation we take ratio of the last two terms
- Now that was the Fibonacci numbers are about
- Now I wanna pose a challenge to you
- I want you to write, since we already done some examples using factorials
- I want you to write an implementation of a function that generate the nth term in the Fibonacci sequence
- So the function will be like this, so this will be the Fibonacci sequence
- So if I call your function (let me make it lower case)
- Let me just give you some examples
- If I take your function and I call fibonacci
- you can really implement this in any language you want
- or we've been dealing in python and like be simples to do it on python
- If I call fibonacci of 1, what I want this to be is the 1st term
- and just to make things clear, you should always clarify this especially in computer science
- because that always clear what the 1st term is
- and I'm going to make it clear right now
- the 1st term is not gonna be this one over here
- I wanna make this one over here, I'm gonna call this the zeroth term
- That's the zeroth term and that is going to be the 1st term
- This is going to be the 2nd term, 3rd term, 4th term so on and so forth
- And so fibonacci of 1, the 1st term will be this right over here
- It will, it should return one
- Fibonacci of 0, so, should return 0
- Fibonacci of 3 should return, 0, 1, 2, 3, it should return 2
- Fibonacci...
- Fibonacci of 5 should return, 0, 1, 2, 3, 4, 5, it should actually return 5
- What I want you to do is to write a function so we could put any argument over here
- and return that term of the Fibonacci sequence

##### 初次見面

##### 好像又更了解你一點了

##### 要常常來找我玩喔！

(1/3)(2/3)(3/3)我是均一小學的課程管家梨棃，會挑選最適合你的內容，讓梨梨更了解你吧！我是老師
我是學生
我是家長

目前主要教導

目前孩子就讀

目前就讀

想蒐集多元備課資料

想透過均一管理學生學習狀況

想透過均一培養學生自主學習

了解均一跟其他教育平台的差異

想找適合孩子學習的內容

想透過均一培養孩子自主學習

與孩子一起規劃學習進度

建立親師溝通的管道

了解均一平台的最大特色

其他

你對哪些內容感興趣呢？（可複選）

數學

自然

電腦

素養

英文

社會

梨梨會定期發送你感興趣的內容

請留下你的 E-mail

載入中...