```
# take input
num = int(input('Enter number of terms: '))
# print fibonacci series
a, b = 0, 1
i = 0
# check if the number of terms is valid
if num <= 0:
print('Please enter a positive integer.')
elif num == 1:
print('The Fibonacci series: ')
print(a)
else:
print('The Fibonacci series: ')
while i < num:
print(a, end=' ')
c = a + b
a = b
b = c
i = i+1
```

Fibonacci Series

Fibonacci series in Python | In the Fibonacci series, the next element will be the sum of the previous two elements. The Fibonacci sequence is a series of numbers where a number is found by adding up the two numbers before it. Starting with 0 and 1, the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so onβ¦

As a rule, the expression is Xn= Xn-1+ Xn-2

## 0 Comments

Add Comment

Log in to add a comment