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
有帮助吗?

解决方案

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

其他提示

You are multiplying to a variable with zero value

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top