I am a newbie to python and cannot understand most of your code, so whatever I didn't understand I have marked in bold. Kindly elaborate.
Thanks!
from itertools import count, islice
import math
def sine_terms(x):
t = x
f = -x ** 2
for n in count(3, 2):
yield t
t *= f /((n-1) * n)
def sine(x, n):
return sum(islice(sine_terms(x), n))
if __name__ == '__main__':
print(sine(6, 25), math.sin(6))
Thanks!
from itertools import count, islice
import math
def sine_terms(x):
t = x
f = -x ** 2
for n in count(3, 2):
yield t
t *= f /((n-1) * n)
def sine(x, n):
return sum(islice(sine_terms(x), n))
if __name__ == '__main__':
print(sine(6, 25), math.sin(6))