def rectangle(b,c):
area_rectangle = b * c
print (area_rectangle)
def triangle(base,height):
area_triangle = 1/2 * (base * height)
print (area_triangle)
a = str(input("Area of what: Triangle or Rectangle? =>"))
if a == "rectangle" or "Rectangle" or "Rec" or "rec":
rectangle((int(input("Please enter base of rectangle:"))),(int(input("Please enter height of rectangle:"))))
elif a == "Triangle" or "triangle":
triangle((int(input("Please enter base of triangle:"))),(int(input("Please enter height of rectangle:"))))
else:
print ("invalid Request")
答案 0 :(得分:0)
使用此:
if a in ["rectangle" ,"Rectangle" ,"Rec" ,"rec"]:
与三角形相同。
发生这种情况是因为在python中
if a == 'x' or 'b' or 'c' or 'd'
与
不同if (a =='x') or (a =='b') or (a == 'c') or ( a == 'd')