Example HTML page

# A Python Program to find the sum of sine series.

In mathematics, the sine is a trigonometric function and is represented as sin( ). In this post I will show you how to write a program to calculate sum of sine series.

Program

```import math
def sin(x,n):
s = 0
for i in range(n):
sign = (-1)**i
pi=22/7
y=x*(pi/180)
s = s + ((y**(2.0*i+1))/math.factorial(2*i+1))*sign
return s
x=int(input("x in degrees: "))
n=int(input("number of terms "+"'n'" ": "))
print(round(sin(x,n),2))

```

Output

 x in degrees: 60 number of terms ‘n’: 3 0.87

Explanation

Take input for degrees and number of terms from the user and is stored in ‘x’ and ‘n’ variables. We defined a ‘sin’ function and those ‘x’ and ‘n’ are passing as arguments in to it. To convert degrees to radians a for loop is used. The sine expansion formula is used to find the value of every term. The statement round(sin(x,n),2 prints the round value of sin(x,n) for two numbers after the decimal point. If you want to print four numbers after the decimal point you can give 4 instead of 2. This process continues till the number of terms is equal to ‘n’ value. Finally the sum of sine series is printed.

Example HTML page