My code is pretty long and I need help condensing it to make it more convenient. The code I have is suppose to do the set of instructions I commanded it to do on a fluke robot. I am using python. The robot is suppose to do the following code using it sensors. I need help condensing it.

EDIT:

My code: 

from Myro import *
from Graphics import *
init('/dev/tty.IPRE6-366079-DevB')

def markYellow(pic):
    for pix in getPixels(pic):
        r = getRed(pix)
        g = getGreen(pix)
        b = getBlue(pix)
        if r &gt; 200 and b &lt; 90 and g &gt; 150:
            setRed(pix,255)
            setGreen(pix,255)
            setBlue(pix,255)
        else:
            setRed(pix,0)
            setGreen(pix,0)
            setBlue(pix,0)

def pctMarked(pic):
    totalPixels = 0
    whitePixels = 0
    for pix in getPixels(pic):
        if getRed(pix) == 255:
            whitePixels = whitePixels + 1
        totalPixels = totalPixels + 1
    result = whitePixels / float(totalPixels)
    return result


def findAvgX(pic):
    pixelCount  = 0
    totalXCount = 0
    for pix in getPixels(pic):
        if getRed(pix) == 255:
            x = getX(pix)
            totalXCount = totalXCount + x
            pixelCount = pixelCount + 1
    avgX = totalXCount / float( pixelCount)
    return avgX


def turn():
    findAvgX(pic)
    if wallLocation &lt;= 85:
        turnLeft(1,0.25)
    elif ballLocation &gt;= 170:
        turnRight(1,0.25)


def celebrate():
    move(0.25,1)
    beep(1,800)
    beep(1,1600)
    beep(1,800)
    stop()

def main():
    p = takePicture()
    markYellow(p)
    pctMarked(p)
    while pctMarked(pic) &lt; 0.2: 
        rotate(1,1)
        p = takePicture()
        markYellow(p)
        pctMarked(p)
    turn()
    while getObstacle('center')&gt; 1000: # I'm not sure about the number. We can test it tomorrow
        forward(1,1)
    celebrate()



Question: Does the strength of a smell depend on the volume or surface area of an agglomerate of material?
Answer: Exposed surface area usually wins out over mass as far as emitting smells, unless you're talking about extremely thin films that "deplete" quickly. As for why you're observing a stronger mass dependence, I suspect there's enough experimental variability that it's hard to get a good measurement. 

However, with the internal channels you get an additional trait absent with the Timberland tread: the ability for material wedged deep inside the channels to stay moist and fester. This  may exacerbate the smell. 

What  manner of material is usually wedged in the shoe?