# lab10.py # YOUR NAME(S) AND NETID(S) HERE # DATE COMPLETED HERE """Loop functions for lab 10""" def numberof(thelist, v): """Returns: number of times v occurs in thelist. Precondition: thelist is a list of ints v is an int""" count = 0 # IMPLEMENT THIS WITH A WHILE LOOP HERE return count def replace_copy(thelist,a,b): """Returns: a COPY of thelist but with all occurrences of a replaced by b. Example: replace([1,2,3,1], 1, 4) is [4,2,3,4]. Precondition: thelist is a list of ints a and b are ints""" copy = [] # IMPLEMENT THIS WITH A WHILE LOOP HERE return copy def replace(thelist,a,b): """MODIFY thelist so that all occurrences of a replaced by b. This function should have NO RETURN STATEMENT Example: if a = [1,2,3,1] then a becomes [4,2,3,4] after the function call replace(a,1,4). Precondition: thelist is a list of ints a and b are ints""" # IMPLEMENT THIS WITH A WHILE LOOP pass # OPTIONAL FUNCTION def cuberoot(c,err=1e-6): """Returns: the (postive) cube root of c to with the given margin of error. Use Newton's Method to find a root of the polynomial f(x) = x^3-c Newton's Method produces a sequence where x_(n+1) = x_n - f(x_n)/f'(x_n) = x_n - (x_n*x_n*x_n-c)/(3x_n*x_n) which we simplify to x_(n+1) = 2*x_n/3 + c/(3*x_n*x_n) We can stop this process and use x_n as an approximation of the square root of c. The error when we do this is less than |x_n*x_n*x_n - c|. So we loop until this error is less than err. Precondition: c, err > 0 is a number.""" # IMPLEMENT THIS WITH A WHILE LOOP return 0 # STUB RETURN