robsanna
robsanna

Reputation: 433

Hackerrank with Python 3.x.x code does not work

I am trying to do some exercises in hackerrank with python. While i code with pyCharm everything seems to work, but in the hackerrank editor i get errors, for example:

arr = [1,2,3,4,5]
k = input()

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

I don't understand how should I code on the hackerrank editor in a way that their input works with my algorithm

thanks for any help

Upvotes: 0

Views: 9522

Answers (2)

Anuj Pratap Singh
Anuj Pratap Singh

Reputation: 209

As we know that function always return something. So, if we use return instead of print function then that will be very professional and efficient.

 arr=[1,2,3,4,5]
    k=int(input())
    def findnumber(arr,k):
        if k in arr:
           return 'YES'
        else:
          return 'NO'
    findnumber(arr,k)

Upvotes: 0

Paras jain
Paras jain

Reputation: 432

Instead of printing the output try to return the output

arr = [1,2,3,4,5]
k = input()

def findNumber(arr, k):
    if k in arr:
        return 'YES'
    else: return 'NO'
findNumber(arr, k)

Upvotes: 3

Related Questions