First,it is giving me syntax error on while loop condition. To get rid of zero division error here, I have given the condition to while loop so that the number will not be equal to zero. Now, I don't know what to do?
def is_power_of_two(number):
while (number!== 0 && number%2!=0):
number = number / 2
if number == 1:
return True
else
return False
print(is_power_of_two(0)) # Should be False
print(is_power_of_two(1)) # Should be True
print(is_power_of_two(8)) # Should be True
print(is_power_of_two(9)) # Should be False
I tried to solve it but it didn't worked.