Search for question
Question

Exercise 4A Write functions to perform the following tasks efficiently. Do not change the function names in

the template file.

(1) Take x and return x³

(2) Take two inputs x and y and return their sum and product, in that order. E.g. inputs 3, 4 should return

7, 12.

(3) Take a list of numbers and returns their arithmetic mean, geometric mean and harmonic mean, in that

order. For example, the input [4,16] should return 10.0, 8.0, 6.4.

(4) Take an integer n and returns a list of the first n of the Narayana's cows sequence Cn. (This is a variant

of the Fibonacci numbers, defined by C₁ = C₂ = C3 = 1, and Cn = Cn-1 + Сn-3 for n ≥ 4.)

(5) Take a pair r≥ 0 and representing a point's polar coordinates and return a pair x, y representing its

Cartesian coordinates.

(6) Take a pair x, y representing a point's Cartesian coordinates and return a pair r, representing its polar

0

coordinates, where 0 = [0, 2π). Check that your function works for (x, y) in all quadrants.