Hi guys,

I got this from my teacher and im really confused. could anyone point me in the right direction?

Thanks

What does it do?

This time I'm looking for an overall summary, in one sentence, with the word "by" in the middle:

"This function ..........., by ................ ."

This function takes a list of numbers as an argument, and returns a list of numbers.
To help you figure it out, cut out 5 or 6 pieces of paper, write some numbers on them, put them on a table, and run the algorithm yourself.

define MyFunction (list):
    for OuterForLoopCounter in 1 to listlength-1:
        for InnerForLoopCounter in 1 to listlength-1:
            if list[InnerForLoopCounter] is greater than list[InnerForLoopCounter+1]:
                swap list[item] and list[item+1]
    return (list)

Edited 3 Years Ago by pyTony: fixed the code formating, use the code button more selectively

Look articles on sorting algorithm based on swapping adjacent items.

Edited 3 Years Ago by pyTony

Let me give you a head start:

def myfunc(l):
    for i in range (1, len(l)-1):
        for j in range (1, len(l)-1):

for

define MyFunction (list):
    for OuterForLoopCounter in 1 to listlength-1:
        for InnerForLoopCounter in 1 to listlength-1:

now, how about implementing the rest:

 if list[InnerForLoopCounter] is greater than list[InnerForLoopCounter+1]:
                swap list[item] and list[item+1]
    return (list)
This question has already been answered. Start a new discussion instead.