Python Forum

Full Version: index out of range
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I took python code for sudoku game and when I run the code i ran to error "out of range" please help me with this one.

import sys
from Sudoku.Generator import *

# setting difficulties and their cutoffs for each solve method
difficulties = {
    'easy': (35, 0), 
    'medium': (81, 5), 
    'hard': (81, 10), 
    'extreme': (81, 15)
}

# getting desired difficulty from command line
difficulty = difficulties[sys.argv[2]] 
I get the following error:

Traceback (most recent call last):
  File "C:/Users/ramit/Desktop/sudoku-generator-master/sudoku-generator-master/sudoku_generator.py", line 14, in <module>
    difficulty = difficulties[sys.argv[2]]
IndexError: list index out of range

Process finished with exit code 1
Python indexes are zero based. So [0] is the first item, [1] is the second item, and [2] is the third item.
even if i change it to [1] same error.
print sys.argv before you try access it. What is it?