Pythonでフィボナッチ数列実装 | Fibonacci Sequence Implementation in Python

Pythonでフィボナッチ数列実装 | Fibonacci Sequence Implementation in Python

日本語

フィボナッチ数列とは

下記のように「前の2つの数を加えると次の数になる」という数列。
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,・・・

実装

a = 0
b = 1
c = 0

for num in range(10):
    a = b
    b = c
    c=a+b
    print(c)
Advertisement

実行結果

1
1
2
3
5
8
13
21
34
55

English

What is the Fibonacci Sequence?

A sequence of numbers that says, “If you add the previous two numbers, you get the next number” as shown below.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,・・・

Implementation

a = 0
b = 1
c = 0

for num in range(10):
    a = b
    b = c
    c=a+b
    print(c)

Result

1
1
2
3
5
8
13
21
34
55

Pythonカテゴリの最新記事