#!/usr/bin/python def odd_powers(n): m = n while True: yield m m = m * n * n def factorials(): n = 6 #start with 3! c = 3 while True: yield n c = c + 1 n = n * c def signs(): s = -1 while True: yield s s = s * (-1) def sine(x): p = odd_powers(x) p.next() #skip first power f = factorials() s = signs() while True: yield x a = p.next() b = f.next() f.next() #skip even factorials c = s.next() x = x + c * a / b s = sine(3.0) while True: try: print str(s.next()) except: break