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 に答える