Python Forum
What's wrong with these codes?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's wrong with these codes?
#1
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) 
Yoriz write Oct-27-2021, 07:42 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Do not post images, use the python button and insert your code .
Reply
#3
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.
Reply
#4
If the for exits, the i += 1 will kill the while loop by raising IndexError at next iteration.
Reply
#5
I solved it. The for loop shouldn't be there. Thanks for replies.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,573 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 3,016 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020