What's wrong with my code?

the problem is from codewars:

My code shows ValueError:

Traceback (most recent call last):
File “main.py”, line 3, in
Test.assert_equals(iq_test(“2 4 7 8 10”),3)
File “/home/codewarrior/solution.py”, line 8, in iq_test
i = int(i)
ValueError: invalid literal for int() with base 10: ‘’

Could you tell me what’s wrong with my code? Why it is showing ValueError? What changes should I make?

def iq_test(numbers):

    even =[]
    odd = []
    
    for i in numbers:
        
        i = int(i)
        
        if (i%2) == 0:
            even.append(i)
        else:
            odd.append(i)
            
    
    if len(even) == 1:
        for i in even:
            index = numbers.index(i)
            index = index + 1
            return index
            
    elif len(odd) == 1:
        for j in odd:
            index = numbers.index(j)
            index = index + 1
            return index

You cannot just convert “2 4 7 8 10” to a list of int as you’re trying to do. You’d need to split it first.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.