Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

SR2019-Buggy-Code

a guest Nov 12th, 2018 85 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. # Implementation of a bubble sort.
  2. # This code is syntactically correct, however there are a couple of
  3. # problems that prevent it from producing the desired output.
  4. # Find these errors and correct them, writing a comment explaining
  5. # what the error was.
  6.  
  7. def swap_values(i1, i2, list_):
  8.     list_[i1], list_[i2] = list_[i1], list_[i1]
  9.     return list_
  10.  
  11. def sort(values):
  12.     for pass_num in range(1, len(values)):
  13.         pass_size = len(values) - pass_num
  14.         for i in range(pass_size + 1):
  15.             if values[i] > values[i + 1]:
  16.                 values = swap_values(i, i, values)
  17.     return values
  18.  
  19. print sort([3, 45, 212, 31, 53, 4])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top