Ad
  • Custom User Avatar

    Correct, this will return False if it is odd and True if it is even. I've seen some more complex mathematical methods to detect if it's a power of two with just simple arithmetic but what would probably be easiest is to import Math and do return False if math.log(n, 2)%1 else True

  • Custom User Avatar

    I think this checks if a number is odd, not if it's a power of two. For example, 12 % 2 is equal to 0, yielding True but 12 is not a power of two.

  • Default User Avatar

    thank you ,this is good way