I have written the below bubble sort code in Python.
def bubble_sort(): num_list=[] list_cnt=input("How many numbers you would like to sort:") for i in range(int(list_cnt)): ### need to convert the value returned by input() num_list.append(input("Enter " +str(i)+" number:")) ##here we are using append method of list print("The values input are as follows:") print(num_list) print(len(num_list)) ### Below new line of code added to convert list to integer### num_list=list(map(int,num_list)) ## with the above line the code is now working as expected## max_index=len(num_list)-1 ## because list begins with 0 print("max_index is:",max_index) for i in range(len(num_list)-1): j=0 swapped=False for j in range(len(num_list)-1): if num_list[j] > num_list[j+1]: num_list[j],num_list[j+1]=num_list[j+1],num_list[j] print("Sorted when j=" +str(j)+ " and i=" + str(i)+ " is:\n ") print(num_list) swapped=True if not swapped: break print("The sorted list is :") print(num_list) bubble_sort()