**Python Programs**

Python Flow Control

➤ Even Number in Python

➤ Odd Number in Python

➤ Even Odd Program

➤ Largest of 3 Numbers

➤ Leap Year Program

➤ Multiplication Table

➤ Factors of a Number

➤ Prime Factors in Python

➤ Factorial of a Number

➤ Factorial using Function

➤ Math.factorial() in Python

➤ Factorial using Recursion

➤ LCM of Two Numbers

➤ HCF/GCD of 2 Numbers

➤ Solve Quadratic Equation

➤ Sum of Digits of a Number

➤ Sum of N Natural Numbers

➤ Fibonacci Series in Python

➤ Fibonacci Series – Recursion

➤ Simple Calculator in Python

➤ Perfect Square in Python

➤ Absolute Value in Python

Conversion Programs

➤ Celsius to Fahrenheit

➤ Fahrenheit to Celsius

➤ Decimal to Binary

➤ Binary to Decimal

➤ Decimal to Octal

➤ Octal to Decimal

➤ Decimal to Hexadecimal

➤ Hexadecimal to Decimal

Array Programs

➤ Linear Search in Python

➤ Binary Search in Python

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…

By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.

As a rule, the expression is **X _{n}= X_{n}-1+ X_{n}-2**

## Fibonacci Sequence in Python

This python program using the **if-else statement** and **while loop** to display the Fibonacci sequence. We will take the n-th term while declaring the variables. Python program to display the Fibonacci sequence using while loop and finally, the result will be displayed on the screen.

```
# Python program to print fibonacci series up to n-th term
# 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
```

Output for the different input values:-

Enter number of terms: 5

The Fibonacci series:

0 1 1 2 3

Enter number of terms: 13

The Fibonacci series:

0 1 1 2 3 5 8 13 21 34 55 89 144

## Fibonacci Series in Python using For loop

In the previous program, we will use the while loop but in this program, display the Fibonacci sequence using **for loop**.

```
# Python program to print fibonacci series up to n-th term
# take input
num = int(input('Enter number of terms: '))
# print fibonacci series
a, b = 0, 1
# 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: ')
for i in range (1, num+1):
print(a, end=' ')
c = a + b
a = b
b = c
```

Output:-

Enter number of terms: 10

The Fibonacci series:

0 1 1 2 3 5 8 13 21 34

## Find nth Fibonacci Number

```
# Python program to find n-th fibonacci number
# take input
num = int(input('Enter number of terms: '))
# print fibonacci term
a, b = 0, 1
# check if the number of terms is valid
if num <= 0:
print('Please enter a positive integer.')
elif num == 1:
print('The Fibonacci term is = ', end='')
print(a)
else:
print('The Fibonacci term is = ', end='')
for i in range (2, num):
c = a + b
a = b
b = c
print(b)
```

Output for the different input values:-

Enter number of terms: 5

The Fibonacci term is = 3

Enter number of terms: 0

Please enter a positive integer.

Enter number of terms: 1

The Fibonacci term is = 0

Enter number of terms: 25

The Fibonacci term is = 46368

We can also find the Fibonacci series using the recursion technique. For more see:- Fibonacci series using recursion

Also See:- Find Factorial of a Number in Python