<jupyter_start><jupyter_text>Part 2: Determine if a number is a power of two.* [Constraints](Constraints)* [Test Cases](Test-Cases)* [Algorithm](Algorithm)* [Code](Code)* [Unit Test](Unit-Test)* [Solution Notebook](Solution-Notebook)  Constraints* Is the input number an int?    * Yes* Can we assume the inputs are valid?    * No* Is the output a boolean?    * Yes* Can we assume this fits memory?    * Yes  Test Cases* None -> TypeError* 0 -> False* 1 -> True* 2 -> True* 15 -> False* 16 -> True  AlgorithmWe can use bit manipulation to determine if a number is a power of two.For a number to be a power of two, there must only be one bit that is a 1.We can use the following bit manipulation trick to determine this:n & (n - 1) Here's an example why:0000 1000 = n0000 0001 = 10000 0111 = n-10000 1000 = n0000 0111 = n-10000 0000 = n & n-1, result = 0  Code<jupyter_code>class Solution(object):

    def is_power_of_two(self, val):

        """self.val = val
        if self.val is None:
            raise TypeError()
        elif self.val == 0:
            return False
        elif self.val == 1:
            return True
        else:
            import math
            return math.log2(self.val).is_integer()"""
        #Above, I used a function from the internet.
        #Then I decided to use my own method:
        
        self.val = val
        if self.val is None:
            raise TypeError()
        elif self.val == 0:
            return False
        elif self.val == 1:
            return True
        elif self.val ==2:
            return True
        else:
            a = []
            for i in range(2, self.val + 1):
                a.append(2 ** i)
            return self.val in a<jupyter_output><empty_output><jupyter_text>Unit Test **The following unit test is expected to fail until you solve the challenge.**<jupyter_code># %load test_is_power_of_two.py
from nose.tools import assert_equal, assert_raises


class TestSolution(object):

    def test_is_power_of_two(self):
        solution = Solution()
        assert_raises(TypeError, solution.is_power_of_two, None)
        assert_equal(solution.is_power_of_two(0), False)
        assert_equal(solution.is_power_of_two(1), True)
        assert_equal(solution.is_power_of_two(2), True)
        assert_equal(solution.is_power_of_two(15), False)
        assert_equal(solution.is_power_of_two(16), True)
        assert_equal(solution.is_power_of_two(31), False)
        assert_equal(solution.is_power_of_two(64), True)
        assert_equal(solution.is_power_of_two(128), True)
        assert_equal(solution.is_power_of_two(203), False)
        print('Success: test_is_power_of_two')


def main():
    test = TestSolution()
    test.test_is_power_of_two()


if __name__ == '__main__':
    main()<jupyter_output>Success: test_is_power_of_two
{'fraction_non_alphanumeric': 0.09836647727272728, 'fraction_numerical': 0.03160511363636364, 'mean_word_length': 2.701708278580815, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '43065', 'license': 'MIT', 'n_tokens_mistral': 955, 'n_tokens_neox': 858, 'n_words': 268, 'path': 'Exam2Part2.ipynb', 'repo_name': 'AmitSamra/RipplesInSpacetime', 'size': '2816'}