Chapter 5 Functions Flashcards

1
Q

A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that called it.
True or False?

A

True

Chapter 5 Q

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

When a function is called by its name during the execution of a program then it is

a. located
b. exported
c. defined
d. executed

A

executed

Chapter 5 Q

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

What will display after the following code is executed?

def main():
    print("The answer is", magic(5))
def magic(num):
    answer = num + 2 * 10
    return answer

main()

a. 70
b. 25
c. 100
d. The statement will cause a syntax error.

A

25

Chapter 5 Q

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

The function header marks the beginning of the the function definition.
True or False?

A

True

Chapter 5 Q

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

It is recommended that programmers avoid using ___ variables in a program whenever possible.

a. local
b. string
c. keyword
d. global

A

global

Chapter 5 Q

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

The randrange function returns a randomly selected value from a specific sequence of numbers.
True or False?

A

True

Chapter 5 Q (page# 247)

The randrange function takes the same arguments as the range function. The difference is that the randrange function does not return a list of values. Instead, it returns a randomly selected value from a sequence of values

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

Unfortunately, there is no way to store and call on functions when using turtle graphics.
True or False?

A

False

Chapter 5 Q

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

Which of the following will assign a random integer in the range of 1 through 50 to the variable ‘number’?

a. number = random.randint(1, 50)
b. randint(1. 50) = number
c. random(1, 50) = number
d. number = random(range(1, 50)

A

number = random.randint(1, 50)

Chapter 5 Q

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

The first line in a function definition is known as the function ___

a. block
b. return
c. header
d. parameter

A

header

Chapter 5 Q

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

A set of statements that belong together as a group and contribute to the function definition is known as a ___

a. block
b. return
c. parameter
d. header

A

block

Chapter 5 Q

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

Different function can have local variables with the same names.
True or false?

A

True

Chapter 5 Q

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

What will be the output after the following code is executer?

def pass_it(x, y):
   z = x, ", ", y
   num 1 = 4
   num2 = 8
   answer = pass_it(num1, num2)
   print (answer)

a. None
b. 8, 4
c. 4, 8
d. 48

A

None

Chapter 5 Q

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

A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that calle it.
True or False?

A

True

Chapter 5 Q

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

To assign a value to a global variable in a function, the global variable must be first declared in the function.
True or False?

A

True

Chapter 5 Q

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

The randrange function returns a randomly selected value from a specific sequence of numbers.
True or False?

A

True

Chapter 5 Q

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

A(n) ___ chart is also known as a structure chart.

a. data
b. hierarchy
c. flow
d. organizational

A

hierarchy

Chapter 5 Q

17
Q

The ___ design technique can be used to break down an algorithm into functions.

a. subtask
b. top-down
c. simplification
d. block

A

top-down

Chapter 5 Q

18
Q

A(n) ___ is any piece of data that is passed into a function when the function is called.

a. parameter
b. local variable
c. global variable
d. argument

A

argument

Chapter 5 Q

19
Q

What type of function can be used to determine whether a number is even or odd?

a. even
b. odd
c. math
d. Boolean

A

Boolean

Chapter 5 Q