I know I could use the sort() function, but I am trying to do this without using that.
from random import randint
# Create variables
numberArray = [0]*20
# Populate array
for i in range(0,20):
numberArray[i] = randint(0,300)
# Sort array into ascending order
print("Sorting array into ascending order...")
sortedAscending = False
while sortedAscending == False:
for i in range(0,20):
sortedAscending = True
if i != (len(numberArray)-1):
if numberArray[i] > numberArray[i+1]:
temp = numberArray[i]
numberArray[i] = numberArray[i+1]
numberArray[i+1] = temp
sortedAscending = False
for j in range(0,20):
print(numberArray[j])
print("END OF ARRAY")
print()
for i in range(0,20):
print(numberArray[i])
It starts sorting the array, but then fails to sort any numbers after a few loops. Please help. Note: the loop with "END OF ARRAY" is for debugging.