Introductory Programming Fall 2004 For next Tuesday you should 1) Work on Homework 5. 2) Read Chapters 6 and 7. Fruitful functions ------------------ At the end of a function call, the stack frame disappears, along with the parameters and local variables. All that's left is 1) any changes the function made, which are called side-effects 2) the return value The functions you have written so far are "void functions" because they don't return anything. Functions that return something are called "fruitful". You have already _used_ several fruitful functions, including the math functions. And you saw some in Amoebas.py: def make_amoeba(world, color='violet'): # make an amoeba with the given color and randomize it a = Amoeba(world) a.color1 = color randomize(a) return a def randomize(a, limit): # choose a random location and move the ameoba there x = random_coordinate(limit) y = random_coordinate(limit) teleport(a, x, y) def random_coordinate(limit): # choose a random number between -limit and limit r = random.uniform(-limit, limit) return r amy = make_amoeba(world, 'pink') Exercise: draw a stack diagram for this code. Exercise: write a function that takes two Amoebas and returns the distance between them. Exercise: write a function that takes two Amoebas and returns True if the distance between them is less than 1.0, and False otherwise.