Starting Out with Python, 3e Ch 4

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

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

What is an accumulator?

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

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

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.

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.

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

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

iteration

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

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

True

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

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.

What is a loop iteration?

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

It is not necessary to initialize accumulator variables. 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

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

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.

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

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

None

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

accumulator

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

augmented assignment

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

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

error traps

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

garbage in, garbage out


Set pelajaran terkait

Audit Chapter 5 Risk Assessment: Internal Control Evaluation

View Set

Biology Exam 2 - Mastering Bio HW

View Set

Ch. 14 Express & Implied Warranties

View Set

L3 Soil components and soil formation

View Set

Cardiovascular Priority Questions

View Set

A&P- The Nervous System mastering questions

View Set

Cranial Nerves, Intracranial Pressure

View Set

geometry a - unit 4: triangles and parallelograms lessons 16-19

View Set

U.S. History: Unit 5-World War 1 (At Home and Away)

View Set

2021 NNAAP Nurse Aide Practice Written Exam, CNA - NNAAP Practice Exam - 2017, CNA Practice Questions 2016, 2018 CNA practice test, Certified Nursing Assistant (CNA) Practice Exam (Edition 2019), NNAAP NURSE AIDE PRACTICE WRITTEN EXAM 2020

View Set