Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在每次迭代后更改函数的参数时进行迭代(python)_Python - Fatal编程技术网

在每次迭代后更改函数的参数时进行迭代(python)

在每次迭代后更改函数的参数时进行迭代(python),python,Python,我编写了以下函数,该函数在每次迭代后都会更改其参数 def thresh (*val): for x in val: return float(x)/100 * 10000.0 print thresh (15,20) 输出:TypeError:float()参数必须是字符串或数字 Desired output: 1500.0, 2000.0 谢谢你的建议。*val是一个列表元组float()只能解析str或float而不能解析tuple 此代码段遍历*val,并返

我编写了以下函数,该函数在每次迭代后都会更改其参数

def thresh (*val):
    for x in val:
        return float(x)/100 * 10000.0

print thresh (15,20)
输出:
TypeError:float()参数必须是字符串或数字

Desired output: 1500.0, 2000.0
谢谢你的建议。

*val
是一个
列表
元组
float()
只能解析
str
float
而不能解析
tuple

此代码段遍历
*val
,并返回计算值列表

def thresh (*val):
    return [float(one_val)/100 * 10000.0 for one_val in val]

您需要迭代
val
,因为它有多个值。同样,除以100乘以10000等于乘以100

def thresh (*val):
     return [x*100.0 for x in val] 

>>> print thresh(15,20)
[1500.0, 2000.0]

什么计算会产生那个输出?这里没有迭代,也没有参数变化。不清楚您想要实现什么。您的问题不清楚,请尝试增强它。
def thresh(*val):return(1000,1500。)
有效,至少在您提供的条件下是有效的:/这个问题对许多人来说是清楚的,我想知道为什么你们不能理解它。OdraEncoded和其他响应者确切地知道问题所在,并立即努力解决问题。也许你们应该看看他们的评论。我所犯的错误是,我没有把VALL看作元组。希望这能解决问题。谢谢。非常感谢@OdraEncoded,我现在理解了我在代码中犯的错误。@Tiger1如果这解决了你的问题,请接受它(大灰色复选框)。如果它没有解决你的问题,但为你指明了正确的方向,请写下你问题的解决方案,作为你自己问题的答案。