功能不起作用

时间:2017-04-26 03:02:02

标签: image python-3.x for-loop if-statement

def findClosestColor(newColor, colorList):

    """Takes in a Color object and a list of Color objects, and it finds
    which color in the list is most similar to newColor. It returns the
    most similar color from the list."""

    currClosest = colorList[0]
    currDist = distance(newColor, currClosest)
    for col in colorList:
        nextDist = distance(newColor, col)
        if nextDist > currDist:
            currClosest = col
            currDist = nextDist
    return currClosest


colors1 = [red, green, blue, yellow, pink, white, black]
c1 = findClosestColor(makeColor(240, 15, 30), colors1)

print(c1)

我正在

  

(r = 0,g = 255,b = 0)而不是(r = 255,g = 0,b = 0)。

1 个答案:

答案 0 :(得分:0)

此行不正确:

if nextDist > currDist:

你必须把它翻到小于:

if nextDist < currDist: