0% found this document useful (0 votes)
50 views

In2Py-02 Functions and Recursions: Yaé Urlrich Gaba

This document provides programming exercises involving functions and recursion in Python. It includes tasks such as: writing functions to calculate mathematical expressions and convert between units; recursively computing powers and the Fibonacci sequence; and a menu-driven program to evaluate factorials or quadratic equations based on user input.

Uploaded by

Isaak Toviessi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

In2Py-02 Functions and Recursions: Yaé Urlrich Gaba

This document provides programming exercises involving functions and recursion in Python. It includes tasks such as: writing functions to calculate mathematical expressions and convert between units; recursively computing powers and the Fibonacci sequence; and a menu-driven program to evaluate factorials or quadratic equations based on user input.

Uploaded by

Isaak Toviessi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Institut de Mathématiques et de Sciences Physiques  IMSP

In2Py-02 Functions and Recursions

Yaé Urlrich Gaba


[email protected]

June 16, 2021

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:

x0 = 1 and xn+1 = x.xn .


Write a function power(x,n) that implements the above recursion.
7. Write code that implements the Fibonacci sequence. Test your program at 100.

You might also like