list index out of range - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: list index out of range (/thread-34786.html) |
list index out of range - OliverG - Aug-31-2021 The python code isnt working because the loop i think isnt doing the things in the right order. Been trying to fix this for 4hours and want to know why it is not working. Help would be appreciated RE: list index out of range - deanhystad - Aug-31-2021 You should include your code in your post, not as a link. You should also post the error message including the entire traceback. You should also provide some example input and any output You've been looking at this for 4 hours. What have you tried to better understand the reason for the error? If you want to loop over the strings in Q1, why not do this? for word in Q1.rsplit(): if word in issues: print("We have identified the problem") break else # Didn't find word in issues humandata = input("We could not find an automated solution for you, please type as much infomation about the issue and we will let a technician sort it out") cases += 1 new_issues.write(str(cases)) new_issues.write(humandata) RE: list index out of range - OliverG - Aug-31-2021 Got it working nvm RE: list index out of range - itsmycode - Sep-03-2021 There are several ways to resolve indexerror in Python. It is not recommended to access the list or an array in any programming by using a hardcoded index value. It often leads to an exception, instead use one of the below best practices.
Checkout an article list index out of range for more details numbers = [1, 2, 3, 4, 6, 8, 10] index = 3 if index < len(numbers): print(numbers[index]) |