#Python function issue

5 messages · Page 1 of 1 (latest)

devout light
#

hi there, i was making a function that will tell us if a number is a power of 2 or not
but when i made it, even when I put a power of 2, the console send:" this number is not a power of 2"
can anyone help ?
here is my script:

////////////////////////////////

def power(nbe):
while nbe !=0:
nbe = nbe/2
print(nbe)
if nbe%2 == 1:
print("this number is a power of 2")
else:
print("this number isn't a power of 2")

num = int(input("enter your number: \n"))
a = num % 2
if a == 0:
power(num)
else:
print("this number is not even")

supple dome
devout light
#

How should it be then?

scarlet ridge
#

You need re-think How power of 2 works

Mathematically your Algorithm is Wrong

devout light
#

OK l'll do this
I'll try to find the good algorithm