0

嗨,我收到 TypeError,我只是不知道为什么......

x=float(40)
base=float(10)
math.log(x, [base])

Traceback (most recent call last):
 File "<string>", line 1, in <fragment>
TypeError: a float is required
4

1 回答 1

3

math.log(x, [base])并不是字面意思“放在base括号中”。这是文档用来表示可选参数的内容。

删除它们,它会工作

math.log(x, base)

此外,您不需要使用float内置函数来声明浮点数。只需在您的数字上添加一个小数部分,它就会变成一个浮点数:

x = 40.0

math.log(x, 10)
于 2013-06-02T19:21:15.837 回答