PythiloEasy · 12 min · Task 40 of 100 · progress kept in this browser

Recognize powers of two

Return True exactly when integer n is a positive power of two. Zero and negatives return False.

for n in [0, 8, 12]:
    print(n, n > 0 and n & (n-1) == 0)
Your task

Return True exactly when integer n is a positive power of two. Zero and negatives return False.