Topic Six Flashcards

(34 cards)

1
Q

Python function names follow the same rules as those for naming variables.

True or False

A

True

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

One reason not to use global variables is that it makes a program hard to debug.

True or False

A

True

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

In Python there is no restriction on the name of a module file.

True or False

A

False

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

The randrange function returns a randomly selected value from a specific sequence of numbers.

True or False

A

True

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

The math function atan(x) returns the tangent of x in radians.

True or False

A

False

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

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

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

A

a. top-down

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

A (n) __________ is a variable that receives an argument that is passed into a function.

a. parameter
b. global variable
c. argument
d. named constant

A

a. parameter

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

A __________ constant is a name that references a value that cannot be changed while the program runs.

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

A

c. global

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

A value-returning function is ________________

a. a function that receives a value when called
b. a single statement that performs a specific task
c. called when you want the function to stop
d. a function that will return a value back to the part of the program that called it

A

d. a function that will return a value back to the part of the program that called it

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

Which of the following statements causes the interpreter to load the contents of the random module into memory?

a. import random
b. load random
c. upload random
d. download random

A

a. import random

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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. number = random(range(1, 50))
d. random(1, 50) = number

A

a. number = random.randint(1, 50)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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. The statement will cause a syntax error.
b. 25
c. 100
d. 70

A

b. 25

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

Which of the following functions returns the largest integer that is less than or equal to its argument?

a. greater
b. floor
c. ceil
d. lesser

A

b. floor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
What will be the output after the following code is executed?
def pass_it(x, y):
    z = x + ", " + y
    return(z)

name2 = “Tony”
name1 = “Gaddis”
fullname = pass_it(name1, name2)
print(fullname)

a. Gaddis Tony
b. Gaddis, Tony
c. Tony, Gaddis
d. Tony Gaddis

A

b. Gaddis, Tony

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
What will be displayed after the following code is executed?
def pass_it(x, y):
    z = x*y
    result = get_result(z)
    return(result)
def get_result(number):
    z = number + 2
    return(z)
num1 = 3
num2 = 4
answer = pass_it(num1, num2)
print(answer)

a. 14
b. Nothing, this code contains a syntax error.
c. 12
d. 9

A

a. 14

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

A group of statements that exist within a program for the purpose of performing a specific task is a (n) ____________

a. block
b. parameter
c. function
d. expression

17
Q

A design technique that helps to reduce the duplication of code within a program and is a benefit of using functions is ______________

a. code reuse
b. divide and conquer
c. debugging
d. facilitation of teamwork

A

a. code reuse

18
Q

The first line of a function definition is known as the ________

a. body
b. introduction
c. initialization
d. header

19
Q

You ___________ a function to execute it.

a. define
b. call
c. import
d. export

20
Q

A design technique that programmers use to break down an algorithm into functions is known as ___________

a. top-down design
b. code simplification
c. code refactoring
d. hierarchical subtasking

A

a. top-down design

21
Q

A _____________ is a diagram that gives a visual representation of the relationships between functions in a program.

a. flowchart
b. function relationship chart
c. symbol chart
d. hierarchy chart

22
Q

A _________ is a variable that is created inside a function.

a. global variable
b. local variable
c. hidden variable
d. none of the above; you cannot create a variable inside a function

A

b. local variable

23
Q

A (n) __________ is the part of a program in which a variable may be accessed.

a. declaration space
b. area of visibility
c. scope
d. mode

24
Q

A (n) __________ is a piece of data that is sent into a function.

a. argument
b. parameter
c. header
d. packet

25
A (n) __________ is a special variable that receives a piece of data when a function is called. a. argument b. parameter c. header d. packet
a. argument
26
A variable that is visible to every function in a program file is a _____________. a. local variable b. universal variable c. program-wide variable d. global variable
d. global variable
27
When possible, you should avoid using __________ variables in a program. a. local b. global c. reference d. parameter
b. global
28
This is a prewritten function that is built into a programming language. a. standard function b. library function c. custom function d. cafeteria function
a. standard function
29
This standard library function returns a random integer within a specified range of values. a. random b. randint c. random_integer d. uniform
b. randint
30
This standard library function returns a random floating-point number in the range of 0.0 up to 1.0 (but not including 1.0). a. random b. randint c. random_integer d. uniform
a. random
31
This standard library function returns a random floating-point number within a specified range of values. a. random b. randint c. random_integer d. uniform
a. random
32
This statement causes a function to end and sends a value back to the part of the program that called the function. a. end b. send c. exit d. return
d. return
33
This is a design tool that describes the input, processing, and output of a function. a. hierarchy chart b. IPO chart c. datagram chart d. data processing chart
b. IPO chart
34
This type of function returns either True or False. a. Binary b. true_false c. Boolean d. logical
c. Boolean