Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

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 I am executing the files, it is just fine on Pycharm, on HackerRank I am getting 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'

1 Answer

0 votes
by (108k points)

Please be informed that your method def findNumber(arr, k): does not yield anything, so it is returning None implicitly.

result = findNumber(arr, k)  

fptr.write(result + '\n')

Don't add None and a string together as it won't work in this case. Rather than printing inside your function, return "Yes" or "No".

Want to be a Python expert? Join this Python Training course by Intellipaat to learn more.

Related questions

Browse Categories

...