代码编译但输出错误。例如,当我输入一个值 45 时,我得到的输出是 1.0。我使用enthought canopy IDE,我哪里出错了?
import math
x = int(raw_input("Enter the size of the angle : "))
y = (x*math.pi)/180
# my factorial function
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
def cos(x):
for i in range (9):
sum = 0
sum += ((-1)**(i)) * (y **(2* i))/factorial((2*i))
return sum
print cos(x)
print y # I wanted to be sure my conversion to radian is right