Nikhil Goud
Nikhil Goud

Reputation: 584

Code exit status 255

I have written the below code for getting the only unique element in a given integer array.

def lonelyinteger(a):
    for x in a:
        answer = a.count(x)
        if(a.count(x) < 2)
            answer=x
    return answer
if __name__ == '__main__':
    a = input()
    b = map(int, raw_input().strip().split(" "))
    print lonelyinteger(b)

Error

File "solution.py", line 5 if(a.count(x) < 2) ^ SyntaxError: invalid syntax

Exit Status 255

Please tell me where did I miss

Upvotes: 1

Views: 12801

Answers (2)

Derick Alangi
Derick Alangi

Reputation: 1100

Correct code below this (your code modified):

def lonelyinteger(a):
    # added a : that was missing in the for
    # loop (syntax error)
    for x in a:
        answer = a.count(x)
        if(a.count(x) < 2):
            answer=x
    return answer
if __name__ == '__main__':
    a = input()
    b = map(int, raw_input().strip().split(" "))
    print lonelyinteger(b)

Upvotes: -1

Scott Hunter
Scott Hunter

Reputation: 49803

You are missing the : at the end of that line.

Upvotes: 3

Related Questions