Python TypeError: 'NoneType' does not support indexing on line 1

57 Views Asked by At

I am using CodeHS Ultra Karel python, and I tried running this code:

image = [ [ 1, 3, 3, 1],
          [ 3, 3, 3, 3],
          [ 1, 3, 3, 3],
          [ 3, 1, 1, 3] ]
colors = ["null","orange","blue","white"]

pos_x = 0
pos_y = 3

def move_plus(n=1):
    global pos_x
    global pos_y
    for i in range(n):
        if front_is_clear():
            if facing_north():
                move()
                pos_y += 1
            elif facing_south():
                move()
                pos_y -= 1
            elif facing_east():
                move()
                pos_x += 1
            else:
                move()
                pos_x -= 1

def paint_coordinates(x,y):
    paint(color[colors[image[y][x]]])

for i in range(4):
    paint_coordinates(pos_x,pos_y)
    move_plus()

This is in a 4x4 Karel world, with Karel starting in the top left. It should have Karel place a color that is listed at a coordinate and move, 4 times. It gives me this error: TypeError: 'NoneType' does not support indexing on line 1

1

There are 1 best solutions below

0
Timeless On BEST ANSWER

I'm discovering what is Karel.

I figured out that the TypeError was due to the way you're defining image in the sandbox.

Try to define it in a single line like below :

image = [[ 1, 3, 3, 1],[ 3, 3, 3, 3],[ 1, 3, 3, 3],[ 3, 1, 1, 3]]          

Output :

enter image description here