dimanche 14 juin 2020

HackerRank Runtime Error in Simple Python 3 if statement

def findNumber(arr, k):
    if k in arr:
        print( "YES" )
    else:
        print( "NO" )

if __name__ == '__main__':


    arr_count = int(input().strip())

    arr = []

    for _ in range(arr_count):
        arr_item = int(input().strip())
        arr.append(arr_item)

    k = int(input().strip())

    result = findNumber(arr, k)

    fptr.write(result + '\n')

    fptr.close()

While this runs just fine on Pycharm, on HackerRank i get the error:

Traceback (most recent call last):
  File "Solution.py", line 42, in <module>
    fptr.write(result + '\n')
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Would really appreciate if you could point out what the error might be.

Aucun commentaire:

Enregistrer un commentaire