hey guys.i have one realy big big problem.. My programming teacher gave my a task to get these functions to work, but i dont know python program so good.. thats why maybe someone of you could help me, and make these 3 functions to work .:).. please!! these lines are not in corect order, and they nedd to be in another place..


for j in range(i, 0, -1):
def bubble(l):
l[j], l[j-1] = l[j-1], l[j]
for j in range(len(l)-1, i, -1):
return l
k = j
def selection(l):
for i in range(0, len(l)):
if not swapped:
break
for i in range(0, len(l)):
if l[j] > l[j-1]:
break
k = i
def insertion(l):
for j in range(i+1, len(l)):
if l[j] < l[j-1]:
l[j], l[j-1] = l[j-1], l[j]
return l
swapped = True
if l[j] < l[k]:
for i in range(1, len(l)):
l, l[k] = l[k], l
return l
swapped = False

Recommended Answers

All 2 Replies

for j in range(i, 0, -1):
def bubble(l):
            l[j], l[j-1] = l[j-1], l[j]
        for j in range(len(l)-1, i, -1):
    return l
                k = j  
def selection(l):
    for i in range(0, len(l)):
        if not swapped:
            break
    for i in range(0, len(l)):
            if l[j] > l[j-1]:
                break
        k = i
def insertion(l):
        for j in range(i+1, len(l)):
            if l[j] < l[j-1]:
                l[j], l[j-1] = l[j-1], l[j]
    return l
                swapped = True
            if l[j] < l[k]:
    for i in range(1, len(l)):
        l[i], l[k] = l[k], l[i]
    return l   
        swapped = False

First thing is that in Python indentation matters and that you can keep in posts by first pushing the Code button before pasting your code.

How about indention for example on lines 18 to 20? How would program go past the return until end of function? Are there any function missing one return?

Second is that you should give some analysis what program should do in you opinion and what kind of test runs have you done to find the problem?

thanks man,.. you rally helped me. thanks!;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.