Ch. 6 Flashcards
defining functions
the part of the program that uses a function is called the
caller
a python function definition begins with
def
a function can send output back to the program with a
return
formal and actual parameters are matched up by
position
which of the following is not a step in the function-calling process
return controls to the point just before the function was called
in python, actual parameters are passed to the functions
by value
if a function returns a value, it should generally be called from
an expression
a function can modify the value of an actual parameter only if it’s
mutable
write a program to print the lyrics of the song ‘old mcdonald’. your program should print the lyrics for five different animals
def old_mcdonald(animal, sound):
print(“Old McDonald had a farm, E-I-E-I-O”)
print(f”And on that farm he had a {animal}, E-I-E-I-O”)
print(f”With a {sound} {sound} here, and a {sound} {sound} there”)
print(f”Here a {sound}, there a {sound}, everywhere a {sound} {sound}”)
print(f”Old McDonald had a farm, E-I-E-I-O\n”)
old_mcdonald(“cow”, “moo”)
old_mcdonald(“duck”, “quack”)
old_mcdonald(“pig”, “oink”)
old_mcdonald(“horse”, “neigh”)
old_mcdonald(“sheep”, “baa”)