What is a group of statements that exists within a program for the purpose of performing a specific task called?

Chapter 5: Function

5.1 What is a function?

- A function is a group of statements that exist within a program for the purpose of

performing a specific task.

5.2 What is meant by the phrase “divide and conquer”?

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

5.3 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.

5.4 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.

5.5 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.

Calling a VOID function

5.6 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.

5.7 What does the phrase “calling a function” mean?

- To call a function means to execute the function.

5.8 When a function is executing, what happens when the end of the function’s block is

reached?

- the end of the function is reached, the computer returns back to the part of the program

that called the function, and the program resumes execution at that point.

5.9 Why must you indent the statements in a block?

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

and ends

5.10 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.

5.11 What is a variable’s scope?

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

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

variable in a different function?

- Yes

Passing arguments to Functions

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

- arguments

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

- parameters

5.15 What is a parameter variable’s scope?

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

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

parameter?

- No

5.17 The following statements call a function named show_data. Which of the statements

passes arguments by position, and which passes keyword arguments?

1. show_data(name='Kathryn', age=25)keyword argument

2. show_data('Kathryn', 25)position

5.18 What is the scope of a global variable?

- the entire program

5.19 Give one good reason that you should not use global variables in a program.

Is a group of statement that perform a particular task?

A function is a group of related statements designed specifically to perform a specific task. Functions make programming easier to decompose a large problem into smaller parts. The function allows programmers to develop an application in a modular way.

What do we call a series of statements that performs a task?

A Function procedure is a series of Visual Basic statements enclosed by the Function and End Function statements. The Function procedure performs a task and then returns control to the calling code.

Is a set of statements used to perform a specific task?

Data Visualization using R Programming A function is a set of statements organized together to perform a specific task.

Which of the following is a group of statements which are part of another statement or functions?

Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way.

Toplist

Neuester Beitrag

Stichworte