Ch. 6 Flashcards

defining functions

1
Q

the part of the program that uses a function is called the

A

caller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

a python function definition begins with

A

def

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

a function can send output back to the program with a

A

return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

formal and actual parameters are matched up by

A

position

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

which of the following is not a step in the function-calling process

A

return controls to the point just before the function was called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

in python, actual parameters are passed to the functions

A

by value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

if a function returns a value, it should generally be called from

A

an expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

a function can modify the value of an actual parameter only if it’s

A

mutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

write a program to print the lyrics of the song ‘old mcdonald’. your program should print the lyrics for five different animals

A

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”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly