在编码参数以创建输出时出现问题

时间:2018-11-04 05:12:55

标签: python

我需要将该等式变成9。下面是一个示例:

a ^ 2-b ^ 2 =(a + b)*(a-b)

5 ^ 2-4-4 ^ 2 =(5 + 4)(5-4)= 9

并且代码必须使用

乘数

print(mult_numbers(add_numbers(5,4),sub_numbers(5,4)))

def add_numbers(a, b):
    result = a + b
    return result

def sub_numbers(a, b):
     Write code to return sum of a and b
    result =  None #Replace None with your code
    return result

有人可以帮我重写代码吗?

def add_numbers(5, 4):
    result = 5 + 4
    return result

def sub_numbers(5, 4):
    # Write code to return sum of a and b
    result =  5-4
    return result
print(mult_numbers(add_numbers(5,4), sub_numbers(5,4)))

我正在接收:

文件“”,第1行

def add_numbers(5, 4):
                ^

SyntaxError:语法无效

1 个答案:

答案 0 :(得分:0)

您不能将数字写为函数参数,必须定义变量来保存参数,这是正确的代码:

def add_numbers(n1, n2):
    result = n1 + n2
    return result

def sub_numbers(n1, n2):
    # Write code to return sum of a and b
    result =  n1-n2
    return result
print(mult_numbers(add_numbers(5,4), sub_numbers(5,4)))