2024-10-02 10:23:35 发布
网友
这里我有一个函数
def celToFah(x): ftemps = [] for i in x: ftemps.append((9/5 * i) + 32) return ftemps
我把它叫做列表理解。在
获取以下错误
“int”对象不可编辑
为什么我会出错?在
celToFah需要一个列表,您将给它一个int。在
celToFah
int
请将celToFah更改为只处理int,如下所示:
def celToFah(x): return 9/5 * x + 32 ctemps = [17, 22, 18, 19] ftemps = [celToFah(c) for c in ctemps]
或者将ctemps直接传递到celToFah:
ctemps
celToFah
需要一个列表,您将给它一个int
。在请将
celToFah
更改为只处理int
,如下所示:或者将
^{pr2}$ctemps
直接传递到celToFah
:相关问题 更多 >
编程相关推荐