6C - Function Within Function - ParamterPassing
6C - Function Within Function - ParamterPassing
1. Create a method name reversemethod to reverse an integer passed to it. Create another
function named isPalindrome to check whether the number passed is palindrome or not.
[Note: A number is a palindrome if its reversal is the same as itself]. Write a test program
that prompts the user to enter an integer and reports whether the integer is a palindrome.
2. The following formula gives the distance between two points, (x1, y1) and (x2, y2) in the
Cartesian plane:
Given the center and a point on the circle, you can use this formula to find the radius of
the circle. Write a program that prompts the user to enter the center and a point on the
circle. The program should then output the circle’s radius, diameter, circumference, and
area. Your program must have at least the following functions:
a. distance: This function takes as its parameters four numbers that represent two points
in the plane and returns the distance between them.
b. radius: This function takes as its parameters four numbers that represent the center
and a point on the circle, calls the function distance to find the radius of the circle, and
returns the circle’s radius.
c. circumference: This function takes as its parameter a number that represents the
radius of the circle and returns the circle’s circumference.(If r is the radius, the
circumference is 2πr.)
d. area: This function takes as its parameter a number that represents the radius of the
circle and returns the circle’s area. (If r is the radius, the area is πr2).
Write a function using that returns the quotient and remainder after dividing two numbers. [Note:
Take care of division by zero]
Default Arguments:
1. Raising a number n to a power p is the same as multiplying n by itself p times. Write a
function called power () that takes an integer for n and an integer value for p, and returns
the result. Use a default argument of 2 for p, so that if this argument is omitted, the
number n will be squared. Write a python program that gets values from the user to test
this function
2. Write a function, mass (density, volume) returns the mass of an object having a density of
‘density’ and a volume of ‘volume’, whereas mass(density)returns the mass having a
density of density and a volume of 1.0 cubic meters. [Mass = Density x Volume]
3. Write a function, repeat ("I'm OK", 10) displays the indicated string 10 times, and repeat
("I'm fine") displays the indicated string 5 times.
4. Write a function to print a count down from n to zero. The default starting value is 7.
Keyword Arguments:
1. Write a function using keyword arguments that returns the maximum of two numbers.
2. Write a function using keyword arguments to calculate the Compound Interest and write
a test function
Arbitrary Arguments:
1. Write a function named helloFriends() to display a message Hello + friendName, to any
number of friends passed to the function
2. Write a function sumUp() to sum up any number of values passed to the function. Test the
function with 3 values and 7 values.
Global Variable:
Write a function that, when you call it, displays a message telling how many times it has been
called: “I have been called 3 times”, for instance. Write a python program that calls this function.
Try implementing this using a global variable to store the count.