fork download
  1. # the main
  2. def main():
  3. # calling list and variables
  4. SCORES = 10
  5. golfScores = list(map(int, input().split(", ")))
  6. if(len(golfScores) != SCORES):
  7. return
  8.  
  9. # calling module to sort with 2 parameters passed
  10. bubbleSort(golfScores, SCORES)
  11.  
  12. # print the final result
  13. print('The sorted order is:', golfScores)
  14.  
  15. # going through the array to sort
  16. def bubbleSort(golfScores, SCORES):
  17. maxElement = SCORES - 1
  18. while (maxElement >= 1):
  19. index = 0
  20. while (index <= maxElement - 1):
  21. while (golfScores[index] > golfScores[index + 1]):
  22. golfScores[index], golfScores[index + 1] = golfScores[index + 1], golfScores[index]
  23. index = index + 1
  24. maxElement = maxElement - 1
  25. return golfScores
  26.  
  27. # a & b passed as ref values to swap
  28. def swap(a,b):
  29. temp = 0
  30. a = b
  31. b = temp
  32. return a,b
  33.  
  34. # call the main to run
  35. main()
Success #stdin #stdout 0.02s 9296KB
stdin
3, 2, 1, 4, 6, 5, 8, 7, 10, 9
stdout
The sorted order is: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]