Functions and modules Flashcards

1
Q

A ___________ variable is created inside a function and cannot be accessed by the statements that are outside the function.

local
insider
global
constant

A

local

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

After the Python interpreter executes the function body, ________.

it jumps to the next function in the module
it prompts the user for the next step
it terminates the program
it returns back to the calling point

A

it returns back to the calling point

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

________ provide the basic means of code reuse.

Functions
Selection structures
Sequences
Variables

A

Functions

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
FALSE

A

TRUE

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

A/an _____________ is any piece of data that is passed into a function when the function is called.

global
scope
local file
argument

A

argument

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

The first line in the function definition is known as the function __________.

header
parameters
block
body
header
A

header

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

Programmers should avoid using ______ variables in their programs when possible.

global
float
integer
constant
string
A

global

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

Different functions cannot have local variables with the same names.

TRUE
FALSE

A

FALSE

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

Python function names follow the same rules for naming variables.

TRUE
FALSE

A

TRUE

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

If a file with the specified name already exists when the file is opened and the file is opened in ‘w’ mode, then an alert will appear on the screen.

TRUE
FALSE

A

FALSE

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

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

TRUE
FALSE

A

TRUE

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

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

TRUE
FALSE

A

TRUE

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

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

TRUE
FALSE

A

FALSE

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

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

TRUE
FALSE

A

TRUE

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

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

TRUE
FALSE

A

FALSE

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

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

subtask
top-down
simplification
block

A

top-down

17
Q

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

parameter
global variable
named constant
argument

A

parameter

18
Q

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

string
global
local
keyword

A

global

19
Q

A value-returning function is

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

A

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

20
Q

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

upload random
load random
download random
import random

A

import random

21
Q

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

number = random(range(1, 50))
random(1, 50) = number
number = random.randint(1, 50)
randint(1, 50) = number
A

number = random.randint(1, 50)

22
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()

70
The statement will cause a syntax error.
25
100
A

25

23
Q

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

greater
lesser
ceil
floor
A

floor

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

Tony Gaddis
Gaddis, Tony
Gaddis Tony
Tony, Gaddis
A

Gaddis, Tony

25
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)
9
12
Nothing, this code contains a syntax error.
14
A

14