Ask coding questions

← Back to all posts
List Index Out Of Range
Brendan23 (166)

First, I know what the list index out of range error is. To see this error, run the repl, do check orders, then go to make food and make one of the foods that had a 1 or more next to it when you checked check orders, then go to serve food and press ENTER, you should get the error.

Answered by Kai_Justice (278) [earned 5 cycles]
View Answer
Kai_Justice (278)

I suggest just enumerating the list, it'll make your code a bit cleaner and clear up any index related confusion.
Lines 130-137:

      # Instead of looking at the size of the "orders_list" list and indexing it this will automatically index and assign the value to the variable "thing"
      for thing in orders_list:
        if thing in orders_list:

I kept the indentation in case you want to copy and paste it.

Brendan23 (166)

@Kai_Justice hmmm...

Traceback (most recent call last):
  File "", line 134, in <module>
ValueError: list.remove(x): x not in list
Kai_Justice (278)

Line 131 is redundant because the variable "thing" is taken directly from the list. Should be changed to: if thing in done_things:

InvisibleOne (2979)

Well, done_things is not a list, it's a dictionary.

Brendan23 (166)

@InvisibleOne why does it give a 'List index out of range` error then?