Python Forum

Full Version: What's wrong with these codes?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
It doesn't work. What's wrong?
list1 = [1, 1]
i = 2
while True:
    terim = list1[i - 1] + list1[i - 2]
    list1.append(terim)
    terim = str(terim)
    for x in terim:
        if len(terim) == 100:
            break
    i += 1    
print(terim) 
Do not post images, use the python button and insert your code .
Not sure what your trying to do but the print is unreachable, it's an infinite while loop, the break only break the for loop.
If the for exits, the i += 1 will kill the while loop by raising IndexError at next iteration.
I solved it. The for loop shouldn't be there. Thanks for replies.