5.7. Definitions and uses¶
Pulling together the code fragments from the previous section, the whole program looks like this:
This program contains two function definitions:
repeat_lyrics. Function definitions get executed just like other
statements, but the effect is to create function objects. The statements
inside the function do not get executed until the function is called,
and the function definition generates no output.
As you might expect, you have to create a function before you can execute it. In other words, the function definition has to be executed before the first time it is called.
If we move the function call above the definition we will get an error.
See what happens if we move the function definitions around so that
repeat_lyrics is defined before
Construct a block of code with two functions. The first function is called printFlavors, which lists the available flavors. The second function should print the products and call the first function. Finally, call the second function. Watch your indentation! Hint: there is one unused code block.