Advanced Programming, Jan-Apr 2012 18 January, 2012 Assignment 0 This assignment will not be evaluated. It is just for practice. When the question asks for a function, you *must* write a function in Python (i.e., def f(x): ... ) Ensure that the function you define has the name indicated in the question. ---------------------------------------------------------------------- 1. Write a Python function "nthprime" such that nthprime(k) computes the k-th prime in the sequence {2,3,5,7,11,...}, starting with index 0. For instance nthprime(1) should return 3, nthprime(5) should return 13 etc. 2. Write a function to compute (positive) square roots upto a given accuracy using binary search. Given x, not necessarily an integer, and a tolerance delta, the initial interval for the square root of x is [0..1] if x < 1 and [0..x] if x >= 1. Start with an estimate e = x/2 for the square root of x. Repeatedly halve the interval, as appropriate, until |x - e**2| <= delta. You may assume that x > 0 and delta > 0. Your function should be called "sqroot" and should take two parameters, x and delta, in that order. 3. Suppose we have two dictionaries d1 and d2 such that the values in each dictionary consist of lists of numbers without duplicates, sorted in ascending order. We can merge d2 into d1 as follows: a. Any key:value that is in d2 but not in d1 is added to d1. b. For any key k that is common to d1 and d2, the new value in d1 is obtained by merging the lists d1[k] and d2[k], discarding duplicates. The merged list should be sorted in ascending order. Write a Python function "dictmerge" such that dictmerge(d1,d2) merges d2 into d1 as described above. For instance, suppose d1 = {'a':[1,2], 'b':[1,3,5]} d2 = {'b':[2,3,4], 'c':[3,4]} Then dictmerge(d1,d2) would result in d1 being transformed to d1 = {'a':[1,2], 'b':[1,2,3,4,5], 'c':[3,4]} If you add code to your file test your function, make sure to *remove* this code when you submit your solution. The Python file you submit should have *only* the function definition. ----------------------------------------------------------------------