Starting Out with Python, 3e Ch 5

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is a local variable?

A variable that is declared within a function and cannot be accessed by statements that are outside of the function. In addition, a local variable cannot be accessed by code that appears inside the function at a point before the variable has been created.

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

function

The first line of a function definition is known as the _______. a. body b. introduction c. initialization d. header

header

What is the purpose of the return statement in a function?

it returns control back to the main function.

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

local variable

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

parameter

What are the variables that receive pieces of data in a function called?

parameters

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

return

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

scope

What is a function?

A function is a group of statements that exist within a program for the purpose of performing a specific task The definition (code) that is written to create a function. It specifies what a function does.

How is access to a local variable restricted?

A local variable belongs to the function in which it is created, and only statements inside that function can access the variable.

This type of function returns either True or False. a. Binary b. true false c. Boolean d. logical

Boolean

A statement in one function can access a local variable in another function. T or F

False

Calling a function and defining a function mean the same thing. T or F

False

In Python you cannot write functions that accept multiple arguments. T or F

False

Why must you indent the statements in a block?

Indentation is required because the Python interpreter uses it to tell where the block begins and ends.

What is a parameter variable's scope?

It is the function in which the parameter is used. All of the statements inside the function can access the parameter variable, but no statement outside the function can access it.

What is a variable's scope?

It is the part of a program in which the variable may be accessed.

When a parameter is changed, does this affect the argument that was passed into the parameter?

No; the changes made to a parameter do not affect the arguments.

A function in Python can return more than one value. T or F

True

In Python, you can specify which parameter an argument should be passed into a function call. T or F

True

When a function is executing, what happens when the end of the function's block is reached?

When the end of the block is reached, the interpreter jumps back to the part of the program that called the function, and the program resumes execution at that point. When this happens, we say that the function "returns".

Is it permissible for a local variable in one function to have the same name as a local variable in a different function?

Yes; Different functions can have local variables with the same names because the functions cannot see each other's local variables.

What is a value-returning function?

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

What is a Boolean function?

a function which returns either True or False. You can use a Boolean function to test a condition, and then return either True or False to indicate whether the condition exists. Boolean functions are useful for simplifying complex conditions that are tested in decision and repetition structures.

A(n) _______ is a piece of data that is sent into a function. a. argument b. parameter c. header d. packet

argument

What are the pieces of data that are passed into a function called?

arguments

The following statements call a function named show_data. Which of the statements passes arguments by position, and which passes keyword arguments? a. show_data ( name= 'Kathryn' , age=25 ) b. show_ data ( 'Kathryn' , 25 )

arguments by position: show_ data ( 'Kathryn' , 25 ) keyword arguments: show_data ( name= 'Kathryn' , age=25 )

You _______ the function to execute it. a. define b. call c. import d. export

call

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

code reuse


Set pelajaran terkait

AZ-800: Administering Windows Server Hybrid Core Infrastructure

View Set

ISDS 3115 Chapter 11 Concept Questions

View Set

MGMT 371 Iowa State- Quiz 5 Ch 11-12

View Set

Intrapartal Period: Fetal Heart Rate Assessment (Ch 9)

View Set

Introductory: Reading and Vocabulary

View Set