1
美好的一天,我在作为一个学校作业正在做这个程序的问题。基本上,菜单功能显示为我想要的,但它不会正确执行任何其他功能。所以如果我输入一个数字,它只是循环回菜单。即使退出选项也不起作用。我真的不明白为什么。它似乎完全遵循我所有示例代码的语法。Python菜单功能不能正常工作
def Menu():
print ("")
print ("CALCULATIONS MENU")
print ("1) AREA (SQUARE)")
print ("2) AREA (RECTANGLE)")
print ("3) AREA (CIRCLE)")
print ("4) PERIMETER (SQUARE)")
print ("5) PERIMETER (RECTANGLE)")
print ("6) PERIMETER (CIRCLE)")
print ("7) EXIT")
Test = input ("Input menu option(1-7): ")
return Test
def ASQ(Height):
print ("")
print ("The area of the square is:", Height * Height)
def AREC(Height, Width):
print ("")
print ("The area of the rectangle is:", Height * Width)
def ACIR(Radius):
print ("")
print ("The area of the circle is:", 3.1415 * Radius**2)
def PSQ(Height):
print ("")
print ("The perimeter of the square is:", Height * 4)
def PREC(Height, Width):
print ("")
print ("The perimeter of the rectangle is:", Width*2 + Height*2)
def PCIR(Diameter):
print ("")
print ("The perimeter of the circle is:", Diameter * 3.1415)
Loop = 1
Selection = 0
while Loop == 1:
Selection = Menu()
if Selection == 1:
ASQ(input("Enter the length of one side: "))
elif Selection == 2:
AREC(input("Enter height: "), input("Enter width: "))
elif Selection == 3:
ACIR(input("Enter radius: "))
elif Selection == 4:
PSQ(input("Enter the length of one side: "))
elif Selection == 5:
PREC(input("Enter height: "), input("Enter width: "))
elif Selection == 6:
PCIR(input("Enter diameter: "))
elif Selection == 7:
Loop = 0
print ("Good bye")
'Test = int(input(“Input menu option(1-7):”))'else'Test'是一个字符串,并不与您的整数进行比较。 –
谢谢。奇怪的是,它们使用的示例代码都没有在类似的情况下定义int。它当然有帮助。现在出现了新的错误,但我认为我走在了正确的道路上。 – nodeg
Python 2:会工作 –