The program is meant to find the odd number in the string by checking if the number can be divided by 2 without a remainder, here is the code:
def iq_test(numbers):
for x in numbers.split():
if x % 2 != 0:
return x
iq_test("1 2 3 4 5")
Here is the error i get when i run the code:
Traceback (most recent call last):
File "python", line 6, in <module>
File "python", line 3, in iq_test
TypeError: not all arguments converted during string formatting
Any help would be appreciated
if x % 2 != 0:-->if int(x) % 2 != 0:(python thinks you're doing string formatting using the percent sign). Btw. you might want to do something else thanreturnsince it'll return after a single trueifand, thus, only process the number 1.