Python菜单功能无法正常工作

时间:2017-02-19 21:28:39

标签: 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")

1 个答案:

答案 0 :(得分:0)

问题:

Test = input ("Input menu option(1-7): ")

Test将用户输入包含为string,因此当您在Test中保存Selection的值并将其与if-statements中的值进行比较时1}},

if Selection == 1:

您正在将intstring进行比较,而int无效。

<强>解决方案:

通过更改

将用户输入转换为Test = input("Input menu option(1-7): ")
Test = int(input ("Input menu option(1-7): "))

if-statements

或 将""中的数字包含在双引号if Selection == "1": 中,如

var info = $("#info");

for (var i = 0; i < 3; i++) {
  $("p").eq(i).on("click", function(event) {
    var reply = [
      " message=message for first p",
      "index = " + $(this).index(),


    ];
    info.append(reply.join(", ") + "<br>");
  });
}