why dont show the result? syntax error not found in PyCharm [on hold]

Refresh

February 2019

Views

18 time

-2
def findsmallest(arr):
smallest = arr[0]
smallest_index = 0
for i in range(1, len(arr)):
    if arr[i] < smallest:
        smallest = arr[i]
        smallest_index = 1
    return smallest_index

def selectionsort(arr):
    newArr = []
    for i in range(len(arr)):
        smallest = findsmallest(arr)
        newArr.append(arr.pop(smallest))
        return newArr

    print(selectionsort([5, 3, 6, 2, 10]))

1 answers

0

Bad отступы, здесь вы идете:

def findsmallest(arr):
    smallest = arr[0]
    smallest_index = 0
    for i in range(1, len(arr)):
        if arr[i] < smallest:
            smallest = arr[i]
            smallest_index = 1
        return smallest_index

def selectionsort(arr):
    newArr = []
    for i in range(len(arr)):
        smallest = findsmallest(arr)
        newArr.append(arr.pop(smallest))
        return newArr

print(selectionsort([5, 3, 6, 2, 10]))

ВЫХОД:

[3]

РЕДАКТИРОВАТЬ:

Следующий оператор должен выйти из определения функции:

print(selectionsort([5, 3, 6, 2, 10]))