This program contains two function definitions: print_lyrics and 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.
def repeat_lyrics():
print_lyrics()
print_lyrics()
def print_lyrics():
print("I'm a lumberjack, and I'm okay.")
print('I sleep all night and I work all day.')
repeat_lyrics()
The lyrics print like normal.
Correct! This doesnβt cause an error because both functions are defined before repeat_lyrics is called.
We get a TypeError.
Incorrect! This will not cause a TypeError because no invalid data types are used. Try again.
We get a NameError.
Incorrect! This will not cause a NameError because both functions are defined before repeat_lyrics is called. Try again.
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.