Ad
  • Default User Avatar

    here's a little hack,
    i&1==0 and i%2==0 are equivalent but i&1 is faster because it uses a bit operator & (AND)
    we care about lsb (least binary digit, ex. 101 is 1 and 1000 is 0) when checking for parity
    odd numbers have lsb=1, even numbers have lsb=0.
    all numbers either end with lsb=1 or 0, therefore we can check parity by equating them to either 1 or 0. we say
    "is lsb of a number equals 1 or 0? if equals 1, then it is odd. if not then even"
    there are other ways.. int(bin(i)[-1]), simply i&1 or bool(i&1), (a^b)&1 returns 1 if a and b dont have same parity
    goodluck :)

  • Default User Avatar

    the numbers is string type. you need to transver it to int type.

  • Default User Avatar

    try ===

  • Default User Avatar
    1. You can't use mod with strings (you're given a string argument and then you're splitting it into characters, you need to use int(num))
    2. That initial string that you've been given contains spaces, which are not convertable to int, so you'll have to account for them
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    You can not iterate through a loop numbers, in your case the variable "numbers" is a string.
    Therefore, you should make a statement under the for loop statement that estabilishes that the variable "num" is an integer.

    You do that by typing:
    num=int(num)

    and then you continue with your if statement.

  • Default User Avatar

    i'm an idiot. that wasn't my 8kyu level, though dunno why i got a fail when even numbers are the outliers (they are mentioned first in code).
    what could i actually use?
    currently using .split() for getting a list, int(), .index().

    anything recommended?

  • Default User Avatar

    u got a string type here.
    i use int(num) - it changes type to int. though, most likely not the best option.

  • Default User Avatar

    I keep getting a 'TypeError: not all arguments converted during string formatting' when I do

    for num in numbers:
        if num % 2 == 0:
    

    Does anyone know what I did wrong?