Fibonacci Series Explained in 50 Seconds | Simple Python Code Series

preview_player
Показать описание
#Fibonacci #PythonProgramming #CodeEminence #CodingTutorial #LearnPython #FibonacciSeries #PythonForBeginners #ShortPythonTutorial #QuickCoding #PythonTips #50SecondTutorial

In this video, you'll learn how to create a simple Fibonacci series using Python in just 50 seconds!
What is the Fibonacci Series?
It’s a sequence where each number is the sum of the two before it, starting from 0 and 1.

Let's define a function `fibonacci(n)` that generates this sequence.

We start with a list: `fib_sequence = [0, 1]`.

After that The `for` loop starts from index 2 and runs until `n`. In each iteration, it calculates the next Fibonacci number by adding the last two values in the sequence (`fib_sequence[i - 1] + fib_sequence[i - 2]`)

Next Appending, The new value is added to `fib_sequence` using `append()`

Next Return, After the loop finishes, the complete Fibonacci sequence is returned.

Let's take as n as 10 in function print(fibonacci(10))`

Let's run the code it prints the first 10 Fibonacci numbers.

Simple and powerful!
If you found this helpful, subscribe for more Python tips!
Рекомендации по теме