Chapter 4 (Python)review for AP Computer Science(APCS)

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is a group of statements that exists within a program for the purpose of performing a specific task? A) a subtask B) a subprocess C) a process D) a function

D

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 if __name__ == '__main__': main() A) 25 B) 70 C) 100 D) The statement will cause a syntax error.

A) 25

A ________ variable is accessible to all the functions in a program file. A) global B) keyword C) string D) local

A) global

A(n) ________ is a variable that receives an argument that is passed into a function. A) parameter B) named constant C) global variable D) argument

A) parameter

The ________ of a local variable is the function in which that variable is created. A) scope B) definition C) space D) global reach

A) scope

What will be the output after the following code is executed? def pass_it(x, y): z = x + ", " + y return(z) name2 = "Julian" name1 = "Smith" fullname = pass_it(name1, name2) print(fullname) A)Smith, Julian B)Julian Smith C)Smith Julian D)Julian, Smith

A) smith, julian

What does the following statement mean? num1, num2 = get_num() A) The function get_num() is expected to return one value and assign it to num1 and num2. B) The function get_num() is expected to return a value for num1 and for num2. C) The function get_num() will receive the values stored in num1 and num2. D) This statement will cause a syntax error.

B) The function get_num() is expected to return a value for num1 and for num2.

A value-returning function is A) a single statement that performs a specific task B) a function that will return a value back to the part of the program that called it C) called when you want the function to stop D) a function that receives a value when called

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

Which of the following functions returns the largest integer that is less than or equal to its argument? A) ceil B) floor C) lesser D) greater

B) floor

Which of the following statements causes the interpreter to load the contents of the random module into memory? A) load random B) import random C) download random D) upload random

B) import random

The first line in a function definition is known as the function A) return B) header C) block D) parameter

B)header

The Python standard library's ________ module contains numerous functions that can be used in mathematical calculations. A) number B) math C) random D) string

B)math

What will be the output after the following code is executed? def pass_it(x, y): z = x , ", " , y num1 = 4 num2 = 8 answer = pass_it(num1, num2) print(answer) A)8, 4 B)48 C)None D)4, 8

C) None

A(n) ________ is any piece of data that is passed into a function when the function is called. A) local variable B) global variable C) argument D) parameter

C) argument

A set of statements that belong together as a group and contribute to the function definition is known as a A) parameter B) header C) block D) return

C) block

When a function is called by its name during the execution of a program, then it is A) located B) defined C) executed D) exported

C) executed

In a value-returning function, the value of the expression that follows the keyword ________ will be sent back to the part of the program that called the function. A) result B) def C) return D) sent

C) return

Python comes with ________ functions that have already been prewritten for the programmer. A) library B) key C) standard D) custom

C) standard

The Python library functions that are built into the Python ________ can be used by simply calling the required function. A) linker B) compiler C) code D) interpreter

D) interpreter

A ________ variable is created inside a function. A) global B) named constant C) constant D) local

D) local

Which of the following will assign a random integer in the range of 1 through 50 to the variable number? A) random(1, 50) = number B) number = random(range(1, 50)) C) randint(1, 50) = number D) number = random.randint(1, 50)

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

(T/F) A local variable can be accessed from anywhere in the program.

False

(T/F) One of the drawbacks of a modularized program is that the only structure you can use in such a program is the sequence structure.

False

(T/F) The math function atan(x) returns one tangent of x in radians.

False

(T/F) The pass keyword is used to pass arguments to a function.

False

(T/F) Unlike other languages, in Python the number of values a function can return is limited to one.

False

(T/F) Different functions can have local variables with the same names.

True

(T/F) In Python you can have a list of variables on the left side of the argument operator.

True

(T/F) The function header marks the beginning of the function definition.

True

(T/F) The math function ceil(x) returns the smallest integer that is greater than or equal to x.

True

(T/F) The randrange function returns a randomly selected value from a specific sequence of numbers.

True

(T/F) To assign a value to a global variable in a function, the global variable must be first declared in the function.

True

(T/F)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

(True/False) Python allows you to pass multiple arguments to a function.

True

Python function names follow the same rules as those for naming variables. (T/F)

True

(T/F) A function definition specifies what a function does and causes the function to execute.

false


Conjuntos de estudio relacionados

Module #4: Entity Relationship (ER) Modeling (Review)

View Set

Foreign Policy - 429 - Final Exam

View Set

Uniform Securities Act Missed Questions

View Set