【发布时间】:2017-10-29 08:02:19
【问题描述】:
我发现很难调用其他函数。例如,如果用户输入calculate(2,3,"+") 我想调用addition() 函数并显示结果。如果用户输入calculate(2,3,"-") 我想调用subtraction() 函数。
这是我的代码
def addition():
if string == "+":
a = num1 + num2
print("addition was performed on the two numbers ", num1, ' and ', num2)
return a
def subtraction():
if string == "-":
s = num1 - num2
print("subtraction was performed on the two numbers ", num1, ' and ', num2)
return s
def multiplication():
if string == "*":
t = num1 * num2
print("multiplication was performed on the two numbers ", num1, ' and ', num2)
return t
def division():
if string == "/":
d = num1 / num2
print("division was performed on the two numbers ", num1, ' and ', num2)
return d
def calculate(num1, num2, string):
str(string)
我希望calculate(num1, num2, string) 调用其他函数。
顺便说一句,如果我的代码让你感到困惑,我很抱歉
**谢谢,多曼迪尼奥。当我在这里粘贴代码时,如果空格搞砸了,干杯**
【问题讨论】:
-
第一件事:修复代码的缩进。
标签: python-3.x