TypeError: 接受一个定位参数,但提供了五个。

2024-09-25 02:37:19 发布

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

def double_preceding(values):

    '''(list of ints)->None

    Update each value in a list with twice
    the preceding value, and the first item
    with 0.

    For example, if x has the value
    [1,2,3,4,5], after calling the
    double_preceding with argument x,
    x would have the value[0,2,4,6,8]

    >>>double_preceding(2,3,4,5,6)
    [0,4,6,8,10]
    >>>double_preceding(3,1,8,.5,10)
    [0,6,2,16,1] 
    '''
    if values != []:
        temp = values[0]
        values[0] = 0
        for i in range(0, len(values)):
            double = 2 * temp
            temp = values[i]
            values[i] = double
    return #None

我做错什么了?我看不出有什么问题,我已经试着解决它一个小时了。在

我修正了密码:

^{pr2}$

Tags: oftheinnoneifvaluedefwith
2条回答

我很好奇为什么您决定传递list的字面值而不是传递一个包含list的变量。例如

x=[1,2,3,4,5]

前双_(x)

这样,你的函数应该可以工作,如果你只是传递它x取决于你在函数内部有什么代码。你能把函数里面的代码贴出来吗?在

您的函数只接受一个参数,而您要将5传递给它。替换:

>>>double_preceding(2,3,4,5,6)
[0,4,6,8,10]
>>>double_preceding(3,1,8,.5,10)
[0,6,2,16,1] 

有:

^{pr2}$

相关问题 更多 >