Python
- key differences between List and Arrays
- Python collections ChainMap
- Array : Find median in an integer array
- Array : Find middle element in an integer array
- Array : Find out the duplicate in an array
- Array : Find print all subsets in an integer array
- Program : Array : Finding missing number between from 1 to n
- Array : Gap and Island problem
- Python collections
- Python Program stock max profit
- Reverse words in Python
- Python array duplicate program
- Coin change problem in python
- Python Write fibonacci series program
- Array : find all the pairs whose sum is equal to a given number
- Find smallest and largest number in array
- Iterate collections
- List comprehensions in Python
- key differences between List and Arrays
- Program: Calculate Pi in Python
- String Formatting in Python
- Python counters
- python tuples
- Python deque
- Python dictionary
- Python Lists
- python namedtuple
Fibonacci series creation in Python
Learn how to write program for Fibonacci series . This is important programming and asked in many pairs programming interviews .
Lets break this down
Here I try to solve this program using recursive practice.
at step 1 : have declared the list having two element 0 and 1 .
as per Fibonacci equation : xn= xn-1 + xn-2
in next steps
created the loop for iterate the length and append the values.
def fibonacci(n):
fib_series = [0, 1] # Starting with the first two numbers in the series
for i in range(2, n):
next_num = fib_series[i - 1] + fib_series[i - 2]
fib_series.append(next_num)
return fib_series
n = 10
fibonacci_series = fibonacci(n)
print(f"Fibonacci series with {n} numbers:", fibonacci_series)
# Output: Fibonacci series with 10 numbers: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]