Question

This while loop is giving me trouble as it simply will not stop, I'm trying to update elem to eventually be larger then char by using an exponent i but that simply doesn't happen and was wondering if there were any solutions.

i = 0
char = 20
elem = 2
while elem < char:
    elem**i
    i += 1
Was it helpful?

Solution

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

OTHER TIPS

You are multiplying to a variable with zero value

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top