Home > Net >  TypeError: insertionSort() got an unexpected keyword argument 'numberList'
TypeError: insertionSort() got an unexpected keyword argument 'numberList'

Time:04-14

i am doing my assigment in python i need to creat function for insertion sort which take input in float and do insertion and also do print list of sorting after every single index is sorted please dont delete post i am newbe and dont understand other solution guide me please i need to input exactly name

insertionSort(numberList=[1.1, 2.2, 3.3, 4.4])

my function is

def insertionSort(intList):
    n = len(intList)
    for i in range(0, n-1):

        kMin = i
    for k in range(i 1, n):
        if (intList[k] < intList[kMin]):
            kMin = k

    if (kMin != i):
        temp = intList[i]
        intList[i] = intList[kMin]
        intList[kMin] = temp

my output need to be exactly like this

**round 1 start: [1.1, 2.2, 3.3, 4.4]↩

round 1 end: [2.2, 1.1, 3.3, 4.4]↩

round 2 start: [2.2, 1.1, 3.3, 4.4]↩

round 2 end: [3.3, 2.2, 1.1, 4.4]↩
round 3 start: [3.3, 2.2, 1.1, 4.4]↩
round 3 end: [4.4, 3.3, 2.2, 1.1]**

CodePudding user response:

You say insertionSort(numberList=[1.1, 2.2, 3.3, 4.4]), but the definition of insertionSort expects a parameter named intList. Either change the name you pass to match the prototype:

insertionSort(intList=[1.1, 2.2, 3.3, 4.4])

change the definition to use the better name (since it clearly works on float):

def insertionSort(numberList):  # And change all uses inside the function to numberList

or just have the caller pass positionally so the name doesn't matter:

insertionSort([1.1, 2.2, 3.3, 4.4])
  • Related