In this piece of code the iterations should stop at one position earlier than they do.
k = 0
while 2^k < 5:
k += 1
print(k)
I expect it to print '3' but it prints out '4'.
In this piece of code the iterations should stop at one position earlier than they do.
k = 0
while 2^k < 5:
k += 1
print(k)
I expect it to print '3' but it prints out '4'.
In Python the ^
operator is bitwise exclusive-or - not exponentiation. Use **
for exponentiation.