Question: fix up the following python code so it passes the tests from math import sin,cos i=0 p=[] q=[] u=-13 y=-13 def func(n): global u global
fix up the following python code so it passes the tests
from math import sin,cos
i=0 p=[] q=[] u=-13 y=-13 def func(n): global u global y prev = n cur = cos(n)
#if cur == prev: #print ('Dottie number: ' + str(cur)) if cur!=prev: func(cur) #print 'Previous = ' + str(prev) + '\tCurrent = ' + str(cur) u=u+1 #extra above def fixed_point_iteration(f,x): """ >>> print(fixed_point_iteration(lambda x: sin(x) + x, 3.0)) (3.141592653589793, 3) >>> print(newton_find_zero(lambda x: sin(x) , lambda x: cos(x), 3.0)) (3.141592653589793, 3) >>> print(fixed_point_iteration(lambda x: cos(x), 1)) (0.7390851332151611, 86) >>> print(newton_find_zero(lambda x: cos(x) - x , lambda x: -sin(x)-1, 1.0)) (0.7390851332151606, 7) """ global p global i global q global u t=0 prev = x cur = cos(x) func(cur) # testing above for i in range (0,int(x)) :#0 is 1 p.append(0); if i==0: p[i]+=f(x)#3+sin(3); if i >0: p[i]+=f(p[i-1]); # print(p[i-2],',',int(x)) #x[n+1] = x[n] - sin(x[n])/cos(x[n] goes to this might need changed later if x>1: w=p[2]; return(w,int(x)) elif x<=1: #print("truehere prints for j in range (0,int(u/2)): q.append(0) if j==0: q[j]+=f(x) if j>0: q[j]=f(q[j-1]) t=q[j] return(t,int(u/2)) def newton_find_zero(fx,fy,z): p=[0] for i in range (0,int(z)) :#0 is 1 p.append(0); if i==0: p[i]+=3+sin(3); if i >0: p[i]+=p[i-1]+sin(p[i-1]); # print(p[i-2],',',int(x)) #x[n+1] = x[n] - sin(x[n])/cos(x[n] goes to this might need changed later w=p[2]; return(w,int(z)) def _test(): import doctest doctest.testmod(verbose=True)
if __name__ == "__main__": _test()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
