Reindeer spotter. Stuck


I have been spending a good amount on this level but I still can’t figure it out. Help will be greatly appreciated
Thank you

# This array contains the positions of the pens that we want to put the reindeer in.
penPositions = [ {'x':20,'y':24}, {'x':28,'y':24}, {'x':36,'y':24}, {'x':44,'y':24}, {'x':52,'y':24} ]

# This array is used to track which reindeer (if any) is in each pen.
penOccupants = [ 'empty', 'empty', 'empty', 'empty', 'empty' ]

# And this array contains our reindeer.
friends = hero.findFriends()

# Figure out which reindeer are already in their pens.
for deerIndex in range(len(friends)):
    reindeer = friends[deerIndex]

# Go through each position and see if it matches the reindeer's position.
for penIndex in range(len(penPositions)):
    penPos = penPositions[penIndex]
    if penPos.x == reindeer.pos.x and penPos.y == reindeer.pos.y:
        # Put the reindeer's ID in the penOccupants array in slot penIndex.
        # break out of the inner loop here to avoid confusion.

# Tell Merek what's in each pen.
for occIndex in range(len(penOccupants)):
    penOccupant = penOccupants[occIndex]
    speech = "pen " + occIndex + " is " + penOccupant
    # Tell Merek the pen index and the occupant.
    # Say something like "Pen 2 is empty" or "Pen 3 is Dasher"


For starters, there’s a structure problem. The second for loop should be inside the first for loop. Tab it over.

Next, refer to the comment,

# Put the reindeer's ID in the penOccupants array in slot penIndex.

You haven’t done that with your code. You’re close but there needs to be an assignment here. You’re supposed to assign the penOccupants[penIndex] a

Do the above and it should work. :grinning:


Thank you @MunkeyShynes