Python+Parameter+Passing

Parameters are passed from the main program into a function / procedure.

We can either pass the value of the actual parameter (by value), or to pass the address of the memory location where the actual parameter is stored (by reference).

When a parameter is passed by value, the original value is not changed.

When a parameter is passed by reference, the value of the parameter is changed.


 * function calculate_room_volume**
 * room_length, room_width and room_height are all passed by value into the function calculate_room_volume
 * room_length, room_width and room height are actual parameters passed from the main program into the function calculate_room_volume
 * r_length, r_width, r_height are formal parameters which take on the value of the 3 actual parameters being passed from the main program
 * calculate_room_volume is a function because it returns a value


 * procedure display_room_volume**
 * room_volume is passed by value into the procedure display_room_volume
 * room_volume is an actual parameter passed from the main program into the procedure display_room_volume
 * r_vol is a formal parameter which take on the value of the actual parameter being passed from the main program
 * display_room_volume is a procedure because it does not return a value

Extension Task
Write a program which:
 * asks the user for the radius of a circle
 * calculates the diameter of the circle
 * calculates the circumference of the circle
 * calculates the area of the circle

The program should have 4 subroutines with data flowing in (parameters) and out (returned) as follows:

name: get_radius in: - out: radius

name: calc_diameter in: radius out: diameter

name: calc_circumference in: diameter out: -

name: calc_area in: radius out: -