CS 110 Lecture 11: calculating sin function in python
Document Summary
# initialize total (sum of the series) to 0. 0. total = 0. 0. # initialize term (each term in the series) to 1. 0, and sign (sign of. # the term) to 1. term = 1. 0 sign = 1. # initialize i (loop variable) to 1. i = 1. # repeat until convergence. while total != total + term: # set term to its previous value times x divided by i. term = (term * x) / i. # if i is odd, increment total by sign * term, and toggle sign. if i % 2 != 0: total += sign * term sign *= -1. Reads a float x (representing an angle in.