About the program
This Python program reads n and computes the following series:
∑ [sin(yᵢ) / (cos(yᵢ) · cos(yᵢ₊₁))] for i from 1 to n
Here we assume yᵢ = i, with angles in radians.
Python code:
import math
def trig_series(n: int) -> float:
total = 0.0
for i in range(1, n + 1):
y_i = i
y_next = i + 1
numerator = math.sin(y_i)
denominator = math.cos(y_i) * math.cos(y_next)
if denominator == 0:
raise ValueError(f"Division by zero at term i={i}")
total += numerator / denominator
return total
# Read the input from the user
n = int(input("Enter n: "))
try:
result = trig_series(n)
print(f"The series result is: {result:.6f}")
except ValueError as e:
print(f"Calculation error: {e}")Sample output (input: n = 3):
The series result is: -1.317240