我给了这个函数两个参数,它说我只给了一个

2024-09-29 06:21:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图解决Coursera(Python)中的这个非常基本的问题:

  1. Write two functions, one called addit and one called mult. addit takes one number as an input and adds 5. mult takes one number as an input, and multiplies that input by whatever is returned by addit, and then returns the result.

我的尝试:

def mult(x,y):
    return x*addit(y)


def addit(x):
    return x+5

The error message:

ERROR None None Error: TypeError: mult() takes exactly 2 arguments (1 given)

Pass 6 6 Testing the function addit with input 1 (should be 6)

Pass 3 3 Testing the function addit with input -2 (should be 3)

Pass 5 5 Testing the function addit with input 0 (should be 5)

所以它传递给了所有测试,但是有一条错误消息说“TypeError:mult()正好接受2个参数(给定1个)”

我真的不明白,我在mult函数中给出了两个参数“x”和“y”


Tags: andthenumberinputwithfunctionpassbe