0
def shapearea():
    shape = raw_input("What shape do you want to print? ")
    if shape == "triangle" or "Triangle":
        return trianglearea()

    elif shape == "circle" or "Circle":
        return circlearea()

    elif shape == "square" or "Square":
        return squarearea()
    else:
        shapearea()

shapearea()

使用此代码会破坏我的程序,我怎样才能让程序注册(例如):

“圆圈”或“圆圈”相同

4

3 回答 3

3
if shape in ("triangle", "Triangle")

或者更好,

if shape.lower() == "triangle"
于 2013-03-24T10:57:03.587 回答
1

替代@jamylak 的答案,这是您需要的:

if shape == "triangle" or shape == "Triangle":
    return trianglearea()

elif shape == "circle" or shape == "Circle":
    return circlearea()

elif shape == "square" or shape == "Square":
    return squarearea()
于 2013-03-24T10:57:23.813 回答
0
So the actual function should be:  
def shapearea():
shape = raw_input("What shape do you want to print? ")
        if shape == "triangle" or shape == "Triangle":
            return trianglearea()

    elif shape == "circle" or shape == "Circle":
        return circlearea()

    elif shape == "square" or shape == "Square":
        return squarearea()
    else:
        shapearea()

shapearea()
于 2013-03-24T11:09:21.563 回答