In2Py-02 Functions and Recursions: Yaé Urlrich Gaba
In2Py-02 Functions and Recursions: Yaé Urlrich Gaba
1. Write a python script that asks the user for the values of x and y and uses these inputs to
compute the numerical value of the expression
√
x2+y
1 .
x + 2 sin y
2. Write a function that given two integers b and n (n is positive), calculates bn without using
python's power operator. Name this function ownpowerfn.py.
PS: What if we do not specify that n has to be positive?
3. Write functions that do the following:
a) Takes two arguments, and computes their arithmetic and geometric means. Name
these functions arithmetic_mean and geometric_mean respectively.
b) Converts degree Celsius to Fahrenheit and vice versa. Name these two functions
celcius_to_fahrenheit and fahrenheit_to_celcius respectively.
c) Converts angle in degrees to radians and vice versa. Name these two functions
degrees_to_radians and radians_to_degrees respectively.
d) Computes the circumference and the area of a circle given the radius.
4. Write functions that do the following:
a) Given two numbers, compute their average and geometrical mean and prints them.
Now write a program that performs this process 10 times, taking as input the means
computed in the previous step. Name this function avggeom.
1
b) Write a function that computes the distance between two points in the plane. Use
it in another program that computes the perimeter and the area of a triangle, given
three points in the plane. Name this function distancefn.
5. Write a program that oers three options to the user:
1.Evaluation of actorial
2.Evaluation of a second degree equation
3. Exit
The user selects one of the options and then the program requests the data needed and
calls the corresponding function to produce a result. The program then repeats the process
until the user says he wants to exit. Name this function fact2nddeg.
6. For a xed real number x and a natural number n, we can dene recursively xn using the
relations: