在列表中查找最大值的总和和位置

Emm*_*mma 0 python list max

我想创建一个函数,在一个数字列表中打印总和和最大值的位置,但我不知道该怎么做...这是我到目前为止开始的:

我使用了一些类似问题的代码.

def maxvalpos(variables):
    max = 0 
    for i in range(len(variables)):
        if variables[i] > max:
            max = variables[i]
            maxIndex = i 
    return (max, maxIndex)

print maxvalpos(4, 2, 5, 10)
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,它只返回该函数只能接受1个参数.谢谢.

Ign*_*ams 5

然后给它一个参数,或修改定义.

print maxvalpos([4, 2, 5, 10])
Run Code Online (Sandbox Code Playgroud)

要么

def maxvalpos(*variables):
Run Code Online (Sandbox Code Playgroud)