fork(1) download
  1. from math import factorial, radians, isclose, sin
  2.  
  3. def seno(x, n=7):
  4. x = radians(x)
  5.  
  6. def termo_geral(x, i):
  7. return ((-1)**i / factorial(2*i+1)) * (x**(2*i+1))
  8.  
  9. def termos(x, n):
  10. for i in range(n):
  11. yield termo_geral(x, i)
  12.  
  13. return sum(termos(x, n))
  14.  
  15. for angle in {0, 30, 45, 60, 90, 120, 180, 230, 270, 320, 360}:
  16. assert isclose(
  17. seno(angle, 21),
  18. sin(radians(angle)),
  19. abs_tol=1e-5
  20. )
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
Standard output is empty