Python ch 3

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A function definition has what two parts?

A function definition has two parts: a header and a block. The header indicates the starting point of the function, and the block is a list of statements that belong to the function.

What is a function?

A function is a group of statements that exist within a program for the purpose of performing a specific task.

What is a global constant? Is it permissible to use global constants in a program?

A global constant is a name that is available to every function in the program. It is permissible to use global constants. Because their value cannot be changed during the program's execution, you do not have to worry about its value being altered.

What is meant by the phrase "divide and conquer?"

A large task is divided into several smaller tasks that are easily performed.

What is a local variable? How is access to a local variable restricted?

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

What is a parameter variable's scope?

A parameter variable's scope is the entire function in which the parameter is declared.

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

Arguments

Why must you indent the statements in a block?

Because the Python interpreter uses the indentation to determine where a block begins and ends

How can functions make the development of multiple programs faster?

Functions can be written for the common tasks that are needed by the different programs. Those functions can then be incorporated into each program that needs them.

How do functions help you reuse code in a program?

If a specific operation is performed in several places in a program, a function can be written once to perform that operation and then be executed any time it is needed.

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

No, it does not.

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

Parameters

What is the scope of a global variable?

The entire program

What is a variable's scope?

The part of a program in which a variable may be accessed

What does the phrase "calling a function" mean?

To call a function means to execute the function.

How can functions make it easier for programs to be developed by teams of programmers?

When a program is developed as a set of functions in which each performs an individual task, then different programmers can be assigned the job of writing different functions.

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

When the end of the function is reached, the computer returns back to the part of the program that called the function, and the program resume execution at that point.

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

Yes, it is permissible.

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)

a. passes by keyword argument b. passes by position

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

argument

You __________ the function to execute it.

call

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

code reuse

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

function

When possible, you should avoid using __________ variables in a program.

global

. A variable that is visible to every function in a program file is a __________.

global variable

The first line of a function definition is known as the __________.

header

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

hierarchy chart

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

local variable

A(n) __________ is a special variable that receives a piece of data when a function is called.

parameter

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

scope

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

top-down design


Ensembles d'études connexes

Punctuating Restrictive and Nonrestrictive Elements

View Set

CH-8 Saving Investment, and the Financial System

View Set

CH 1 - important of business ethics

View Set