Test 2 - Ch. 4-6

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

A(n) _______ is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list. a. sentinel b. flag c. signal d. accumulator

sentinel

This is math module function. a. derivative b. factor c. sqrt d. differentiate

sqrt

What happens if the same seed value is always used for generating random numbers?

the random number functions would always generate the same series of pseudorandom numbers.

When the random module is imported, what does it use as a seed value for random number generation?

the system time from the computer's internal clock

A design technique that programmers use to break down an algorithm into functions is known as _______. a. top-down design b. code simplification c. code refactoring d. hierarchical subtasking

top-down design

This standard library function returns a random floating-point number within a specified range of values. a. random b. randint c. random_integer d. uniform

uniform

What is a condition-controlled loop?

A condition-controlled loop causes a statement or set of statements to repeat as long as a condition is true. In Python you use the "while" statement to write a condition-controlled loop. The while loop gets its name from the way it works: while a condition is true, do some task.

What is a count-controlled loop?

A count-controlled loop iterates a specific number of times. In Python you use the "for" statement to write a count-controlled loop. The for statement is designed to work with a sequence of data items. When the statement executes, it iterates once for each item in the sequence.

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 the scope of a global variable?

A global variable can be accessed by any statement in the program file, including the statements in any function.

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.

What is an infinite loop?

A loop that has no way of ending and repeats until the program is interrupted.

What is a sentinel?

A sentinel is a special value that marks the end of a sequence of values.

Why should you take care to choose a distinctive value as a sentinel?

A sentinel value must be distinctive enough that it will not be mistaken as a regular value in the sequence.

What is a global variable?

A variable that is created by an assignment statement that is written outside all the functions in a program file.

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.

What is a void function?

A void function is a group of statements that exist within a program for the purpose of performing a specific task. When you need the function to perform its task, you call the function. This causes the statements inside the function to execute. When the function is finished, control of the program returns to the statement appearing immediately after the function call.

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

Boolean

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

Dividing a large program or task into several smaller tasks that are easily managed and performed.

What is a loop iteration?

Each execution of the body of a loop is known as an iteration

A flowchart shows the hierarchical relationships between functions in a program. T or F

False

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

Function names should be as short as possible. T or F

False

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

False

It is not necessary to initialize accumulator variables. T or F

False

The phrase " divide and conquer" means that all of the programmers on a team should be divided and work in isolation. T or F

False

The process of input validation works as follows: when the user of a program enters invalid data, the program should ask the user "Are you sure you meant to enter that?" If the user answers "yes," the program should accept the data. T or F

False

To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops. T or F

False

You cannot have both keyword arguments and non-keyword arguments in a function call. T or F

False

A function definition has what two parts?

Function Header; Block

How can functions make the development of multiple programs faster?

Functions can be written for the commonly needed tasks, and those functions can be incorporated into each program that needs them.

What does the phrase "garbage in, garbage out" mean?

GIGO; refers to the fact that computers cannot tell the difference between good data and bad data. If a user provides bad data as input to a program, the program will process that bad data and, as a result, will produce bad data as output. The integrity of a program's output is only as good as the integrity of its input.

Describe the steps that are generally taken when an input validation loop is used to validate data.

Get input Validate input Input = good? Go to next Input = bad? Display error, get input again

This is a design tool that describes the input, processing, and output of a function. a. hierarchy chart b. IPO chart c. datagram chart d. data processing chart

IPO chart

A(n) _______ variable keeps a running total. a. sentinel b. sum c. total d. accumulator

accumulator

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 )

The -= operator is an example of a(n) _______ operator. a. relational b. augmented assignment c. complex assignment d. reverse assignment

augmented assignment

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.

Why is it critical that accumulator variables are properly initialized?

If the accumulator starts with any value other than 0, it will not contain the correct total when the loop finishes.

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

A _______-controlled loop uses a true/false condition to control the number of times that it repeats. a. Boolean b. condition c. decision d. count

condition

A _______-controlled loop repeats a specific number of times. a. Boolean b. condition c. decision d. count

count

What is a function definition?

The definition (code) that is written to create a function. It specifies what a function does.

What is a priming read? What is its purpose?

The first input operation-just before the loop-is called a priming read, and its purpose is to get the first input value that will be tested by the validation loop.

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

The reasons are as follows: • Global variables make debugging difficult. Any statement in a program file can change the value of a global variable. If you find that the wrong value is being stored in a global variable, you have to track down every statement that accesses it to determine where the bad value is coming from. In a program with thousands of lines of code, this can be difficult. • Functions that use global variables are usually dependent on those variables. If you want to use such a function in a different program, most likely you will have to redesign it so it does not rely on the global variable. • Global variables make a program hard to understand. A global variable can be modified by any statement in the program. If you are to understand any part of the program that uses a global variable, you have to be aware of all the other parts of the program that access the global variable.

What is a seed value?

The value that initializes a formula. The seed value is used in the calculation that returns the next random number in the series.

What is an accumulator?

The variable used to keep the running total is called an accumulator.

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 that each performs an individual task, then different programmers can be assigned the job of writing different functions.

What is the advantage of using a sentinel?

When processing a long sequence of values with a loop, a better technique is to use a sentinel. A sentinel is a special value that marks the end of a sequence of items. When a program reads the sentinel value, it knows it has reached the end of the sequence, so the loop terminates.

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

How does a value-returning function differ from the void functions?

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

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

it returns control back to the main function.

Each repetition of a loop is known as a(n) _______. a. cycle b. revolution c. orbit d. iteration

iteration

This is a prewritten function that is built into a programming language. a. standard function b. library function c. custom function d. cafeteria function

library 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

Should an accumulator be initialized to any specific value? Why or why not?

Yes, to 0. the first step is to set the accumulator variable to 0. This is a critical step. Each time the loop reads a number, it adds it to the accumulator. If the accumulator starts with any value other than 0, it will not contain the correct total when the loop finishes.

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.

What is a global constant?

a global name that references a value that cannot be changed.

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

The while loop is a _______ type of loop. a. pretest b. no-test c. prequalified d. post-iterative

pretest

The input operation that appears just before a validation loop is known as the a. prevalidation read. b. primordial read. c. initialization read. d. priming read.

priming read

This standard library function returns a random integer within a specified range of values. a. random b. randint c. random_integer d. uniform

randint

This standard library function returns a random floating-point number in the range of 0.0 up to 1.0 (but not including 1.0). a. random b. randint c. random_integer d. uniform

random

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 library function?

a prewritten function that performs commonly needed tasks. Python, as well as most other programming languages, comes with a standard library of functions that have already been written for you. These functions, known as library functions, make a programmer's job easier because they perform many of the tasks that programmers commonly need to perform.

Why are library functions like " black boxes" ?

Because you do not see the internal workings of library functions, the term "black box" is used to describe any mechanism that accepts input, performs some operation (that cannot be seen) using the input, and produces output.

Does the while loop test its condition before or after it performs an iteration?

Before; The while loop is known as a pretest loop, which means it tests its condition before performing an iteration.

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.

Give a general description of the input validation process.

Input validation is the process of inspecting data that has been input to a program, to make sure it is valid before it is used in a computation. Input validation is commonly done with a loop that iterates as long as an input variable references bad data.

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.

What is a repetition structure?

More commonly known as a loop, a repetition structure causes a statement or set of statements to execute repeatedly as many times as necessary.

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.

If the input that is read by the priming read is valid, how many times will the input validation loop iterate?

None

What does the phrase "calling a function" mean?

To execute a function, a function call is required. "Calling a function" is a statement that is used to invoke (execute) the function at required places in a program.

A condition-controlled loop always repeats a specific number of times. T or F

True

A hierarchy chart does not show the steps that are taken inside a function. T or F

True

Functions make it easier for programmers to work in teams. T or F

True

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

True

In a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loop. T or F

True

The following statement subtracts 1 from x: x = x - 1 T or F

True

The while loop is a pretest loop. T or F

True

Validation loops are also known as: a. error traps. b. doomsday loops. c. error avoidance loops. d. defensive loops.

error traps

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

GIGO stands for a. great input, great output b. garbage in, garbage out c. GIGahertz Output d. GIGabyte Operation

garbage in, garbage out

When possible, you should avoid using _______ variables in a program. a. local b. global c. reference d. parameter

global

A variable that is visible to every function in a program file is a _______. a. local variable b. universal variable c. program-wide variable d. global variable

global variable

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

header

A _______ is a diagram that g1ves a visual representation of the relationships between functions in a program. a. flowchart b. function relationship chart c. symbol chart d. hierarchy chart

hierarchy chart (also called a 'structure chart').

What import statement do you need to write in a program that uses the math module?

import math; In order to call a function that is stored in a module, you have to write an import statement at the top of your program. An import statement tells the interpreter the name of the module that contains the function.

A(n) _______ loop has no way of ending and repeats until the program is interrupted. a. indeterminate b. interminable c. infinite d. timeless

infinite

The integrity of a program's output is only as good as the integrity of the program's a. compiler . .b. programming language. c. input. d. debugger.

input


Ensembles d'études connexes

Saunders Mental Health and Pharmacology Psychiatric

View Set

2.1.8 - Safety and Protection - Practice Questions

View Set

Descubre 2 Chapter 2 Test review

View Set

LearningCurve 14c. Social-Cognitive Theories and the Self

View Set