-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSinCos.py
More file actions
29 lines (27 loc) · 784 Bytes
/
SinCos.py
File metadata and controls
29 lines (27 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import math
def sin(x,n):
sine=0
i=0
for i in range(n+1):
sign= (-1)**i
sine=sine+ ((x**(2.0*i+1))/math.factorial(2*i+1))*sign
return sine
def cos(x,n):
cosine=0
i=0
for i in range(n+1):
sign= (-1)**i
cosine=cosine+ ((x**(2.0*i))/math.factorial(2*i))*sign
return cosine
print("Sum of Sine/Cosine Series")
choice=int(input("Press 0 for Sum of Sine Series, 1 for Sum of Cosine Series."))
if(choice==0):
x=int(input("Enter the value of x in radians: "))
n=int(input("Enter the number of terms: "))
print(sin(x,n))
elif(choice==1):
x=int(input("Enter the value of x in radians: "))
n=int(input("Enter the number of terms: "))
print(cos(x,n))
else:
print(" operation cannot be performed")