Python Forum
How to fix list index out of range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix list index out of range
#4
The program takes input as command line arguments.
Output:
python program.py 14 12 7 6 p
Replace "program" with the name of your program.

If you want to modify the program so it takes user input instead of using command line arguments you need to replace these lines:
# change these to get user input instead of using command line args in input_list
self.goal_labels = [int(input_list[0]), int(input_list[1])]
self.forbidden_label = int(input_list[2])
self.wall_label = int(input_list[3])

    input_list = sys.argv   # Remove
    input_list.pop(0)  # Remove
    board = Board(input_list)  # Remove input_list
 
    # Get this as user input instead of command line args
    if (len(input_list) == 5) and (input_list[4] == 'p'):
        q_learn(board, True, 0)
    elif (len(input_list) == 6) and (input_list[4] == 'q'):
        q_learn(board, False, int(input_list[5]))
    else:
        print('Invalid input, please run again.')
Reply


Messages In This Thread
How to fix list index out of range - by longmen - Apr-13-2022, 02:28 AM
RE: How to fix list index out of range - by longmen - Apr-15-2022, 03:54 AM
RE: How to fix list index out of range - by deanhystad - Apr-15-2022, 03:09 PM
RE: How to fix list index out of range - by longmen - Apr-18-2022, 03:12 PM
RE: How to fix list index out of range - by longmen - Apr-20-2022, 01:54 AM
RE: How to fix list index out of range - by longmen - Apr-23-2022, 07:02 PM
RE: How to fix list index out of range - by longmen - Apr-24-2022, 02:25 AM
RE: How to fix list index out of range - by longmen - Apr-24-2022, 02:51 PM
RE: How to fix list index out of range - by longmen - Apr-24-2022, 03:42 PM
RE: How to fix list index out of range - by longmen - Apr-24-2022, 05:22 PM
RE: How to fix list index out of range - by longmen - Apr-24-2022, 10:45 PM
RE: How to fix list index out of range - by longmen - Apr-25-2022, 12:20 AM
RE: How to fix list index out of range - by longmen - Apr-25-2022, 02:22 AM
RE: How to fix list index out of range - by longmen - Apr-25-2022, 05:44 PM
RE: How to fix list index out of range - by longmen - Apr-27-2022, 05:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  list index out of range OliverG 3 2,422 Sep-03-2021, 12:04 AM
Last Post: itsmycode
  Index List a04j 2 2,997 Jul-10-2021, 01:14 PM
Last Post: BashBedlam
  List index out of range when turning CSV into dict ranbarr 15 6,778 May-12-2021, 10:38 AM
Last Post: ranbarr
  List vs index: Frederico_Caldas 5 3,729 Jul-03-2020, 10:55 AM
Last Post: DeaD_EyE
  To find the index of the first occurrence of the key in the provided list Angry_bird89 4 3,374 Jun-20-2020, 06:53 PM
Last Post: Angry_bird89
  list index out of range mcgrim 2 2,987 May-25-2019, 07:44 PM
Last Post: mcgrim
  IndexError: list index out of range abdullahali 4 3,973 Jan-17-2019, 07:54 AM
Last Post: buran
  String index out of range felie04 2 5,637 Aug-17-2018, 11:18 PM
Last Post: felie04
  Accessing data in zip - Index out of range pythoneer 24 13,155 Mar-15-2018, 06:19 PM
Last Post: buran
  "List index out of range" for output values pegn305 3 5,409 Nov-26-2017, 02:20 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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