如何在pow()函数中表示x值

问题描述 投票:-1回答:1

我正在尝试在python中表示一个函数。

功能是:

(x^2)-(y+1)^2

pow()函数不能接受字符串作为参数。

我已尝试以此方式表示它:

math.pow(x,2)- math.pow(y+1,2)

但出现错误:

TypeError: must be real number, not str

有没有办法在python中做到这一点?

python python-3.x
1个回答
0
投票

xy转换为int(或float,如果适用)。

math.pow(int(x), 2) - math.pow(int(y) + 1, 2)
© www.soinside.com 2019 - 2024. All rights reserved.