Python don';不管输入是什么,它都不会';“我不能去那家公司。”;否则,如果;陈述

Python don';不管输入是什么,它都不会';“我不能去那家公司。”;否则,如果;陈述,python,python-3.x,Python,Python 3.x,我的输出是menu()函数只会一次又一次地打印,不管输入是什么,它都不会到达“else if”语句 def menu(): #print what options you have print ("Welcome to calculator.py") print ("your options are:") print (" ") print ("1) Addition") print ("2) Subtraction") print ("3

我的输出是menu()函数只会一次又一次地打印,不管输入是什么,它都不会到达“else if”语句

def menu():
    #print what options you have
    print ("Welcome to calculator.py")
    print ("your options are:")
    print (" ")
    print ("1) Addition")
    print ("2) Subtraction")
    print ("3) Multiplication")
    print ("4) Division")
    print ("5) exposion")
    print ("6) Quit calculator.py")
    print (" ")
    return input ("Choose your option: ")
# this adds two numbers given
def add(a,b):
    print (a, "+", b, "=", a + b)
# this subtracts two numbers given
def sub(a,b):
    print (b, "-", a, "=", b - a)
# this multiplies two numbers given
def mul(a,b):
    print (a, "*", b, "=", a * b)
# this divides two numbers given
def div(a,b):
    print (a, "/", b, "=", a / b)
# HERE IS MY CODE
def dinami(base, exponent):
    if y == 1:
        print (base, "*" ,power,"(",base,",", exponent," - 1) = ",base)
    if y != 1:
        print (base, "*" ,power,"(",base,",", exponent," - 1) = ",base * power(base, exponent - 1))   
# NOW THE PROGRAM REALLY STARTS, AS CODE IS RUN
loop = 1
while loop == 1:
    choice = menu()
    if choice == 1:
        add(input("Add this: "),input("to this: "))
        print ("hi")
    elif choice == 2:
        sub(input("Subtract this: "),input("from this: "))
    elif choice == 3:
        mul(input("Multiply this: "),input("by this: "))
    elif choice == 4:
        div(input("Divide this: "),input("by this: "))
    elif choice == 5:
        dinami(input("expone this: "),input("to this: "))
    elif choice == 6:
        loop = 0
print ("Thankyou for using calculator.py!")
input()
返回一个字符串,因此如果将
int
string
进行比较,即
'1'==1
,它总是返回False

input()
返回一个字符串,因此如果将
int
string
进行比较,即
'1'==1
,则始终返回False


对我来说似乎还行-你面临的问题是什么,因为你没有真正解释好答案是输入是字符串,所以我将其转换为整数。对我来说还行-你面临的问题是什么,因为你没有真正解释好答案是输入是字符串,所以我转换了它变为整数