我为我的小示例应用程序获得的输出如下:
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)