class Solution:
# @param {integer} n
# @return {boolean}
def isPowerOfTwo(self, n):
return True if n == 1 else (False if n == 0 else n % 2 == 0 and self.isPowerOfTwo(n/2))

27 certainly can be divided by 2. The result is 13. It wouldn't be done, though, since the n % 2 == 0 would fail before and thus it wouldn't even come to that division.

This approach analyzes the bit pattern, and dividing by 2 is the same as shifting to the right by one bit.