def bubble(n):
change = False
while change == False:
for p in range(n - 1):
j1 = list[p]
j2 = list[p + 1]
if j1 > j2:
list[p] = j1
list[p + 1] = j2
else:
list[p] = j2
list[p + 1] = j1
change = true
return(n)
import random
number = []
for a in range(20):
number.append(random.randint(1, 100))
bubble(number)
Traceback (most recent call last):
File "C:\eclipse\workspace\bubble test 1\test 1", line 20, in <module>
bubble(number)
File "C:\eclipse\workspace\bubble test 1\test 1", line 5, in bubble
for p in range(n - 1):
TypeError: unsupported operand type(s) for -: 'list' and 'int'
Help me understand what I am doing wrong.
This post has been edited by atraub: 14 August 2012 - 07:45 PM
Reason for edit:: fixed code tags

New Topic/Question
Reply



MultiQuote





|