相关疑难解决方法(0)

如何在Python中将字符串转换为int?

我为我的小示例应用程序获得的输出如下:

Welcome to the Calculator!
Please choose what you'd like to do:
0: Addition
1: Subtraction
2: Multiplication
3: Division
4: Quit Application
0
Enter your first number: 1
Enter your second number: 1
Your result is:
11
Run Code Online (Sandbox Code Playgroud)

这是因为addition()方法将input()作为字符串而不是数字.我如何将它们用作数字?

这是我的整个脚本:

def addition(a, b):
    return a + b

def subtraction(a, b):
    return a - b

def multiplication(a, b):
    return a * b

def division(a, b):
    return a / b

keepProgramRunning = True

print "Welcome to the Calculator!"

while keepProgramRunning:    
    print "Please …
Run Code Online (Sandbox Code Playgroud)

python string int

11
推荐指数
2
解决办法
10万
查看次数

标签 统计

int ×1

python ×1

string ×1