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()
使用此代码会破坏我的程序,如何让程序注册(例如):
“circle”或“Circle”为相同的
答案 0 :(得分:3)
if shape in ("triangle", "Triangle")
或更好,
if shape.lower() == "triangle"
答案 1 :(得分: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()
答案 2 :(得分: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()