Bubble Sort Program in Python

Bubble sort program in python. Firstly, we must aware that what is Bubble sort ? Bubble Sort is the sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. This python project is useful for beginners and CBSE KV School Class 11 and Class 12 students computer science practical file and NIELIT O Level Programming and Problem Solving through Python ( Module M3-R5),Computer science B SC and B Tech.

Objective of the program

Write a function to input a list and arrange the list in ascending order using Bubble sort. This python program with source code is discussed in this post.

The source code screenshot and the source code is given at the last of column in this post

Program of Bubble sort in Python

Explanation of source code
l=eval(input(“Enter the list to arrange”)) # first a list is inputted
for i in range(len(l)-1): # first for loop i=0 to len(l)-1
for j in range(len(l)-1): #nested for loop from loop i=0 to len(l)-1
if l[j]>l[j+1]: #comparision between first and the next number if condition is true
l[j],l[j+1]=l[j+1],l[j] #if first one is true then this are swipped
print(“Arranged list :”,l) #The list is printed in asending using bubble sort

Output of bubble sort program in python

Program of Bubble sort in Python

Testing of the program

Here we input the list [9,8,7,6,3,4] and the arranged list [3,4,6,7,8,9].

Test again and this time input is [6,3,9,8,5,6,1,1] and arranged ascending list is [1,1,3,5,6,6,8,9]

Our Bubble Sort program in python language is working fine.

Source code-> click here

for more python programs -> click here

Hello World Program in Python

Input a welcome message and display it in Python

Display the larger / smaller number in Python.

Greatest of Three Numbers in Python using Nested if

Patterns using nested loop in Python

Program to Print Pattern in Python

Program to input the value of x and n and sum of series in Python

Python Program for Armstrong, Prefect Number, Palindrome

Program of Prime number by recursion in python

Prime Number Program in Python

Write a Program to Print Fibonacci Series in Python

LCM and GCD program in Python

Python program to count number of vowels in a string

Whether a String is Palindrome or not in Python

Bubble Sort Program in Python

Linear search in python using list

Program to read a text file in python

Python program to read a file line by line

Program to Count Vowels and Consonants in Python

Stack Program in Python

Queue Program in Python

Python Leap Year Program for Beginners

Python Program to Print Series and Addition

Binary Search Program in Python

Program to find sum of digits in python

Sum of numbers divisible by 3 and 5 in python