Reputation: 53
I want to calculate (π/4)^2-sin(π/4) in python:
import math
a=((math.pi)^2/16)-math.sin(math.pi/4)
print(a)
It gives the error:
TypeError: unsupported operand type(s) for ^: 'float' and 'float'
I also tried using
a=float(((math.pi)^2/16)-math.sin(math.pi/4))
But still doesn't work
Upvotes: 0
Views: 60
Reputation: 40057
No sense in evaluating pi/4 twice.
import math
pi4 = math.pi/4
a = pi4**2 - math.sin(pi4)
Upvotes: 0
Reputation: 66
^ is not supported in python. Instead, you can use math.pow or **
math.pow(math.pi,2)
math.pi ** 2
Upvotes: 1
Reputation: 178
^
is not supported in python. Instead, you can use math.pow
.
import math
a=(math.pow((math.pi),2)/16.0)-math.sin(math.pi/4)
print(a)
Upvotes: 1