Drop The Flag Please Help!

Im currently stuck on the level Drop the Flag and I cant see whats wrong with this:

loop:
flag = self.findFlag()
if flag:
if flag.colour is “black” :
self.buildXY(“fire-trap”, flag.pos.X, flag.pos.Y)
self.pickUpFlag(flag)

else:
    item = self.findNearestItem()
    if item:
        itemPos = item.pos
        itemX = itemPos.x
        itemY = itemPos.y
        self.moveXY(itemX, itemY)

Please help.

Ignore that I’ve completed it.