This Python program reads two values x and n and computes the result of the following trigonometric series:
∑ [tan⁽ᵏ⁾(x) / sin(x⁽ⁿ⁻ᵏ⁺¹⁾)] for k from 1 to n
The angle x is converted to radians, and math.tan and math.sin are used for calculations.
import math
def trig_series(x_deg: float, n: int) -> float:
x_rad = math.radians(x_deg)
total = 0.0
for k in range(1, n + 1):
numerator = math.tan(x_rad) ** k
denominator = math.sin(x_rad ** (n - k + 1))
if denominator == 0:
raise ValueError(f"Division by zero at term k={k}")
total += numerator / denominator
return total
# Read inputs from user
x = float(input("Enter value for x (in degrees): "))
n = int(input("Enter value for n: "))
try:
result = trig_series(x, n)
print(f"Series result is: {result:.4f}")
except ValueError as e:
print(f"Error in calculation: {e}")
Series result is: 3.0463