The problem is that you are not changing the value of elem
, you are just repeatedly calculating elem**i
, so when you compare elem
to char
it is always the same result. The simplest solution is to compare elem**i
to char
.
You probably meant:
while elem**i < char:
i += 1