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
Comments
hotnewtop
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:
          correct_ords+=1
          orders_list.remove(thing)
          done_things.remove(thing)
          orders[thing]-=1
          done_thingss[thing]-=1

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

Brendan23 (166)

@Kai_Justice hmmm...

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

@Brendan23
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?