0

I import two different functions in a separate file but getting Unexpected output.

bubbleSort.py

def checkInputs(n, array):
    if n == len(array) and len(array) > 1:
        for i in range(0, len(array)):
            array[i] = int(array[i])
        removeDups = list(set(array))
        sortArray = bubbleSort(removeDups)
        print(sortArray[len(sortArray) - 2])
    else:
        print("please enter correct values")


def bubbleSort(unSortArray):
    for i in range(len(unSortArray)):
        swap = False
        for j in range(0, len(unSortArray) - i - 1):
            if unSortArray[j] > unSortArray[j + 1]:
                swap = unSortArray[j]
                unSortArray[j] = unSortArray[j + 1]
                unSortArray[j + 1] = swap
                swap = True
        if swap == False:
            break
    return unSortArray

test.py

from bubbleSort import checkInputs, bubbleSort

print(checkInputs(5, [1, 2]))

screenshot of output enter image description here

As you can see in screenshot None in the second line output screenshot, why?

Community
  • 1
  • 1
sarvesh kumar
  • 183
  • 11
  • 4
    Because `checkInputs` is not returning any values. – Austin Sep 19 '19 at 17:06
  • 2
    Inside `check_inputs`, you are printing the result and returning Nothing (`None`). So when you say `print(check_inputs(...))`, you run `check_inputs`, which prints the string, but then the return value of `check_inputs(...)` is printed... which is `None`. – SyntaxVoid Sep 19 '19 at 17:07
  • @Austin, @SyntaxVoid Ahh! thanks for the quick response, I am a Java guy, start learning python, So return statement is mandatory in every function, means generally other `void()` in java, otherwise it is give `None`. – sarvesh kumar Sep 19 '19 at 17:12

0 Answers0