Chapter 4 CSC121

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What are the values that the variable num contains through the iterations of the following for loop? for num in range(4):

0, 1, 2, 3

What will be displayed after the following code is executed? for num in range(0, 20, 5): num += num print(num)

30

What will be displayed after the following code is executed? total = 0 for count in range(4,6): total += count print(total)

4 9

What will be displayed after the following code is executed? total = 0 for count in range(1,4): total += count print(total)

6

A while loop is called a pretest loop because the condition is tested after the loop has had one iteration.

False

In Python, an infinite loop usually occurs when the computer accesses an incorrect memory address.

False

The acronym ______ refers to the fact that the computer cannot tell the difference between good data and bad data.

GIGO

A good way to repeatedly perform an operation is to write the statements for the task once and then place the statements in a loop that will repeat as many times as necessary.

True

Both of the following for clauses would generate the same number of loop iterations. for num in range(4): for num in range(1, 5):

True

In a nested loop, the inner loop goes through all of its iterations for each iteration of the outer loop.

True

The integrity of a program's output is only as good as the integrity of its input. For this reason, the program should discard input that is invalid and prompt the user to enter valid data.

True

A variable used to keep a running total is called a(n)

accumulator

A(n) ________-controlled loop causes a statement or set of statements to repeat as long as the condition is true.

condition

What type of loop structure repeats the code based on the value of Boolean expression?

condition-controlled loop

What type of loop structure repeats the code a specific number of times?

count-controlled loop

What will be displayed after the following code is executed? count = 4 while count < 12: print("counting") count = count + 2

counting counting counting counting

A(n) ________ loop usually occurs when the programmer does not include code inside the loop that makes the test condition false.

infinite

A(n) ________ validation loop is sometimes called an error trap or an error handler.

input

In Python, a comma-separated sequence of data items that are enclosed in a set of brackets is called

list

The while loop is known as a(n) _______ loop because it tests the condition before performing an iteration.

pretest

A(n) ________ is a special value that marks the end of a sequence of items

sentinel

What are the values that the variable num contains through the iterations of the following for loop? for num in range(2, 9, 2):

2, 4, 6, 8

Functions can be called from statements in the body of a loop and loops can be called from within the body of a function.

False

The first line in a while loop is referred to as the condition clause.

False

To get the total number of iterations in a nested loop, add the number of iterations in the inner loop to the number in the outer loop.

False

__________ is the process of inspecting data that has been input into a program in order to ensure that the data is valid before it is used in a computation.

Input validation

What does the following program do? student = 1 while student <= 3: total = 0 for score in range(1, 4): score = int(input("Enter test score: ")) total += score average = total/3 print("Student ", student, "average: ", average) student += 1

It accepts 3 test scores for each of 3 students and outputs the average for each student.

Reducing duplication of code is one of the advantages of using a loop structure.

True

In Python, you would use the _______ statement to write a count-controlled loop.

for

The first operation is called the __________ and its purpose is to get the first input value that will be tested by the validation loop.

priming read

The _____ function is a built-in function that generates a list of integer values.

range

A(n) ________ structure causes a set of statements to execute repeatedly.

repetition

A(n) _______ total is a sum of numbers that accumulates with each iteration of the loop

running

When will the following loop terminate? while keep_on_going != 999:

when keep_on_going refers to a value equal to 999

Which of the following represents an example to calculate the sum of numbers (that is, an accumulator), given that the number is stored in the variable number and the total is stored in the variable total?

total += number


Kaugnay na mga set ng pag-aaral

Codes, Standards and Practices 2, lvl 2 - Class Questions

View Set

Abeka English Literature Appendix quiz Y

View Set