Reputation:
Here is my code thus far,
from math import *
def main():
sides = eval(input("Enter the number of sides:"))
value = 360/(2 * sides)
sinvalue = sin(value)
PI = sinvalue * sides
print("Approximate value of pi =", PI)
However, I am not getting the proper value that is in the sample code.
Upvotes: 1
Views: 1946
Reputation: 362687
math.sin
expects angles to be specified in radians.
>>> print(math.sin.__doc__)
sin(x)
Return the sine of x (measured in radians).
You are specifying it in degrees. Specify the angle in radians instead:
value = math.pi / sides
Or, if you don't want to use math.pi
so explicitly, use the helper function to convert units:
value = math.radians(360/(2*sides))
Upvotes: 3