I'm completing this Codewars exercise. Here are the instructions:
You are given an array (which will have a length of at least 3, but could be very large) containing integers. The integers in the array are either entirely odd or entirely even except for a single integer N. Write a method that takes the array as an argument and returns N.
For example:
[2, 4, 0, 100, 4, 11, 2602, 36]
Should return: 11
[160, 3, 1719, 19, 11, 13, -21]
Should return: 160
However, when I submit the following code:
def ifeven(list):
#Determine if we are dealing with list of evens or odds
sum = 0
for ran in (0,1,2):
sum += abs(list[ran])%2
avg = sum/3
r_avg = round(avg)
return r_avg == 0
def find_outlier(integers):
even = ifeven(integers)
new = []
for num in integers:
new.append(num%2)
if even:
loc = new.index(1)
else:
loc = new.index(0)
return integers[loc]
With this test case (see exercise link):
test.assert_equals(find_outlier([1,2,3]), 2)
For some I reason I get the error 1 should equal 2
even though if I run the code on another compiler, I get 2
as the (correct) answer.
Is the issue with my code or Codewars's compiler?