#bubble sort using indefinite iteration #on a randomly generated list of numbers #where the number can be repeated #running many times will give an idea as #to efficiency import random maxValue = int(input("Numbers from 1 to what? ")) listLength = int(input("How many numbers do you want in your list? ")) theList = [] while len(theList) < listLength: number = random.randint(1, maxValue) theList.append(number) print("Here's the list before sorting:") print(theList) print() input("Press any key to sort it") print() swap = True passes = 0 while swap: swap = False passes = passes + 1 for i in range(0, len(theList)-1): if theList[i] > theList[i+1]: theList[i], theList[i+1] = theList[i+1], theList[i] swap = True print("sorted") print(theList) print(passes)