-1

Hey guys I need some help, I keep on getting a "list index out of range" error even though the index is in range I even wrote a piece of code to print the intext for the word I'm referring to which is 'horror' and it confirms its in index 2 but when I put it under a if statement it gives me the error.


genre = input('What genre do you feel like watching?\n''horror\n''psychological horror\n''adventure\n''action\n''Enter one of the genre seen above here: ')

for item in anime_series_list:
    if item[0] == genre:  
        print(''.join(anime_series_list[0]))
    if item[2] == genre:  
        print(''.join(anime_series_list[2]))
    if item[1] == genre: 
        print(''.join(anime_series_list[1]))
    else:
        print('INVALID OPTION')
        break'''
0x5453
  • 12,753
  • 1
  • 32
  • 61
Rick Sky
  • 3
  • 2
  • 1
    Can you show what the array looks like? – jacky la mouette Aug 17 '22 at 19:36
  • 5
    Please show all your relevant code, like how `anime_series_list` is created and what it contains. – wkl Aug 17 '22 at 19:36
  • 1
    Please provide enough code so others can better understand or reproduce the problem. – Community Aug 17 '22 at 20:00
  • If you are getting an IndexError then you **are** trying to access an item that does not exist. [How to step through Python code to help debug issues?](https://stackoverflow.com/questions/4929251/how-to-step-through-python-code-to-help-debug-issues) If you are using an IDE **now** is a good time to learn its debugging features Or the built-in [Python debugger](https://docs.python.org/3/library/pdb.html). Printing *stuff* at strategic points in your program can help you trace what is or isn't happening. – wwii Aug 17 '22 at 20:58
  • [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – wwii Aug 17 '22 at 20:58

1 Answers1

0

It seems that at least one of the values listed in anime_series_list contains 3 elements. What if you printed out the length of each value? That should help you figure out where the problem is.

for item in anime_series_list:
    if len(item) < 3:
        # print the item so you know which item the length is referring to
        print(item)
        print(len(item))

UberLax
  • 11
  • 3
  • This does not look like an answer. – wwii Aug 17 '22 at 20:56
  • I actually ended up changing the entire structure of the program after learning about pandas the next day and now Im back with another problemhttps://stackoverflow.com/questions/73429025/while-loops-ignoring-if-statements. please help if you can. – Rick Sky Aug 20 '22 at 18:19