Python 3.x 用python计算一个简单的表达式

Python 3.x 用python计算一个简单的表达式,python-3.x,Python 3.x,我想计算(π/4)^2-sin⁡(π/4)在python中: import math a=((math.pi)^2/16)-math.sin(math.pi/4) print(a) 它给出了错误: TypeError: unsupported operand type(s) for ^: 'float' and 'float' 我也试过使用 a=float(((math.pi)^2/16)-ma

我想计算(π/4)^2-sin⁡(π/4)在python中:

import math
a=((math.pi)^2/16)-math.sin(math.pi/4)
print(a)
它给出了错误:

TypeError: unsupported operand type(s) for ^: 'float' and 'float'                                                 
我也试过使用

a=float(((math.pi)^2/16)-math.sin(math.pi/4))
但还是不行


python中不支持
^
。相反,您可以使用
math.pow

import math
a=(math.pow((math.pi),2)/16.0)-math.sin(math.pi/4)
print(a)

python中不支持
^
。相反,您可以使用
math.pow

import math
a=(math.pow((math.pi),2)/16.0)-math.sin(math.pi/4)
print(a)

python中不支持^。相反,您可以使用math.pow或**

math.pow(math.pi,2)


python不支持
math.pi**2

^。相反,您可以使用math.pow或**

math.pow(math.pi,2)


math.pi**2

两次评估pi/4没有意义

import math
pi4 = math.pi/4
a = pi4**2 - math.sin(pi4)

两次评估pi/4没有意义

import math
pi4 = math.pi/4
a = pi4**2 - math.sin(pi4)

哦也许我应该用**而不是^?哦也许我应该用**而不是^?我用了**,但它给出了错误的答案!**的问题是什么?我也用了math.pow,它给出了同样的错误答案。它给出-0.09025,但在计算器中,它表示0.6031**与功率2的功率相同。我尝试用python(-0.09025656561846259)和calculator(-0.090256565611)执行相同的代码,我得到了相同的响应,计算器中的值最多为11位。我不知道为什么我的计算器会给出这个答案。您可以清除计算器的内存,然后重试。或者,使用在线计算器。共享的响应来自在线计算器。我使用了**,但它给出了错误的答案!**的问题是什么?我也用了math.pow,它给出了同样的错误答案。它给出-0.09025,但在计算器中,它表示0.6031**与功率2的功率相同。我尝试用python(-0.09025656561846259)和calculator(-0.090256565611)执行相同的代码,我得到了相同的响应,计算器中的值最多为11位。我不知道为什么我的计算器会给出这个答案。您可以清除计算器的内存,然后重试。或者,使用在线计算器。共享的响应来自在线计算器。