Â
In this we are going to see a program To Find If the Given Number Is Power Of 2 or not in Python Programming Language.
data = []
def is_power_of_2(n):
if n == 0:
return False
while n != 1:
if n % 2 != 0:
return False
n = n // 2
return True
def find_power_of_2(n):
if is_power_of_2(n):
return n
else:
for i in range(1, n+1):
if is_power_of_2(i):
data.append(i)
return data
print(find_power_of_2(10))
# Coded By DHIRAJ SHELKE
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP