Chapter 4 Python

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

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

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.

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

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

In a decision structure, the action is _______________ executed because it is performed only when a certain condition is true.

conditionally

When using the _____ operator, one or both subexpressions must be true for the compound expression to be true.

or

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

pretest

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

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

sentinel

In Python, the variable in the for clause is referred to as the ________ because it is the target of an assignment at the beginning of each loop iteration.

target variable

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? total = 0 for count in range(4,6): total += count print(total)

4 9

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 flowchart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that is tested

True

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

Which of the following is the correct if clause to use to determine whether choice is other than 10?

if choice != 10:

Which of the following is the correct if clause to determine whether y is in the range 10 through 50?

if y > 10 and y < 50

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

list

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

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

infinite

Which logical operators perform short-circuit evaluation?

or, and

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

when keep_on_going refers to a value equal to 999

determines whether a specific relationship exists between two values

Relational operator

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

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

A Boolean variable can reference one of two values: _____.

true or false


Kaugnay na mga set ng pag-aaral

Chap 71 Mass Casualty and Disaster Preparedness

View Set

Series and Sequences Review (chapter 10 precalc honors)

View Set