Deck 3: Loops and Selection Statements

Full screen (f)
exit full mode
Question
The not operator has a lower precedence than the and and or operators.
Use Space or
up arrow
down arrow
to flip the card.
Question
The comparison operators are applied after addition but before assignment.
Question
Conditional iteration requires that a condition be tested within the loop to determine whether the loop should continue.
Question
"A"
Question
The augmented assignment operations have a higher precedence than the standard assignment operation.
Question
When the step argument is a negative number, the range function generates a sequence of numbers from the first argument down to the second argument plus 1.
Question
A condition expresses a hypothesis about the state of its world at that point in time.
Question
There are two types of loops-those that repeat an action a predefined number of times (definite iteration) and those that perform the action until the program determines that it needs to stop (indefinite iteration).
Question
For the most part, off-by-one errors result when the programmer incorrectly specifies the lower bound of the loop.
Question
The or operator returns True if and only if both of its operands are true, and returns False otherwise.
Question
Loop statements allow a computer to make choices.
Question
Simple Boolean expressions consist of the Boolean values True or False, variables bound to those values, function calls that return Boolean values, or comparisons.
Question
The assignment symbol can be combined with the arithmetic and concatenation operators to provide augmented assignment operations.
Question
The statements in the loop body need not be indented and aligned in the same column.
Question
4 != 4 evaluates to True.
Question
The if-else statement is the most common type of selection statement.
Question
The not operator expects a single operand and returns its logical negation, True, if it's false, and False if it's true.
Question
The simplest form of selection is the if-else statement.
Question
The Boolean data type is named for the twentieth-century British mathematician George Boole.
Question
In Python, = means equals, whereas == means assignment.
Question
Some computer scientists argue that a while True loop with a delayed exit violates the spirit of the while loop.
Question
Given the following statement: "%4d" % var1, which of the following is accurate?

A) The variable var1 must be an integer value.
B) The variable var1 must be a string value.
C) The variable var1 will be in octal format.
D) The variable var1 will be formatted regardless of type.
Question
In evaluating a loop, you find the following statement: "value += 1". What happens to the value variable upon each iteration of the loop?

A) The variable is reset to an int type, with a value of 1.
B) The variable's value is changed to a positive value.
C) The variable is increased by 1 each iteration through the loop.
D) The variable is incremented by itself.
Question
What statement should you use to print the value of total with a precision of 5 digits?

A) print("The total is %5." % total)
B) print("The total is %0.5d" % total)
C) print("The total is %f" % float(total, 5))
D) print("The total is %0.5f" % total)
Question
Although the while loop can be complicated to write correctly, it is possible to simplify its structure and thus improve its readability.
Question
What are the two different types of loops that are used within the Python language? (Choose two.)

A) predetermined looping
B) definite iteration
C) infinite cycling
D) indefinite iteration
Question
What comparison operator is used to test whether an expression does NOT equal another expression?

A) -=
B) !=
C) /=
D) _=
Question
What is the minimum number of spaces that should be used to create an indented statement?

A) one space
B) two spaces
C) three spaces
D) four spaces
Question
In a conditional iteration loop, such as a while loop, what is a sentinel value?

A) A sentinel value is a user-provided input value that proceeds to the next loop.
B) A sentinel value is a user-provided input value that changes the structure of the loop.
C) A sentinel value is a special value provided by the user to terminate the loop.
D) A sentinel value is a special value provided by the user to restart the loop.
Question
If A is True, what will the statement "not A" return?

A) Undefined
B) True
C) False
D) BooleanError
Question
What is a one-way selection statement in the context of Python?

A) It is a single if statement without a corresponding else statement used to test a condition and run statements, then proceed to the next statement.
B) It is a single if-else statement block that is used to test a condition and run statements, as well as provide a default path for execution.
C) It is a switch statement block that is used to direct the flow of data based on a single condition.
D) It is an if statement that tests no conditions, but provides a block for execution.
Question
You are running a Python script and suspect that the script has entered an infinite loop. What key combination can you use to halt the loop?

A) CTRL + Esc
B) CTRL + c
C) Alt + b
D) CTRL + Break
Question
What character is used as the format operator when formatting output?

A) ^
B) $
C) %
D) @
Question
When using the range function, what effect does the specification of a third argument have?

A) The third argument is used as the starting point for the range function.
B) The third argument specifies a step value to be used in the range.
C) The third argument declares an exponential value the numbers will be raised to.
D) The third argument is simply included in the sequence, assuming it wasn't already in the range.
Question
The while loop is also called a sentinel-control loop, because its condition is tested at the top of the loop.
Question
Inside of a loop, after a termination condition has been met, what statement can be used to cause an exit from the loop and execute the remainder of the script?

A) exit
B) break
C) quit
D) halt
Question
The while loop is also known as what kind of a loop?

A) infinite loop
B) operational loop
C) user-control loop
D) entry-control loop
Question
A while loop can be used for a count-controlled loop.
Question
An off-by-one error is an example of what type of error in programming?

A) logic error
B) syntax error
C) type error
D) input error
Question
The statements within a while loop can execute one or more times.
Question
What scenario would it make logical sense to use a multi-way selection statement for?

A) You need to convert numeric grades to letter grades.
B) You need to test if the value of A is larger than B.
C) You need to determine if a number is positive or negative.
D) You need to test if a variable is True or False.
Question
Assuming that the value of x is 4, and the value of y is 6, what is the value of the following expression? (x - y)**2 > y

A) True
B) False
C) Undefined
D) TypeError
Question
The use of +=, -=, and *= are all examples of what type of operators?

A) protracted assignment operators
B) augmented assignment operators
C) extended arithmetic operators
D) overloaded mathematic operators
Question
What is NOT a Boolean or logical operator used in the Python language?

A) and
B) or
C) not
D) xor
Question
In programming, what is a prototype?

A) It is a rough draft of a program.
B) It is a program in final stages of development.
C) It is a program statement that builds a module.
D) It is a production-ready program.
Question
In general terms, what does a selection statement do?

A) It forces a computer to favor one value over another.
B) It allows a computer to make choices based on test conditions.
C) It allows a computer to select the values that are most economical.
D) It allows a computer to selectively execute based on processing cost.
Question
What function call will generate a random number in the range of 1 through 6 using the random module?

A) random.randnum(1, 6)
B) random.randint(range(1-6))
C) random.randint(1, 6)
D) random.random(1, 6)
Question
What statement regarding precedence of operators is accurate?

A) The assignment operator (=) is higher in precedence than exponentiation (**).
B) The logical conjunction (and) is higher in precedence than the logical negation (not).
C) The comparison operators (==, !=, , =) are higher in precedence than the assignment operator (=).
D) The addition and subtraction operators (+, -) are lower in precedence than the logical conjunction operator (and).
Question
What part of the loop comprises the statements to be executed?

A) The loop header.
B) The loop body.
C) The loop end.
D) The loop tail.
Question
What is a count controlled loop?

A) It is a loop that counts iterations until a sentinel value is received.
B) It is a loop that continues based on a certain time interval.
C) It is a loop that prints out a count of values for the user.
D) It is a loop that counts through a range of numbers to control when the loop ends.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Loops and Selection Statements
1
The not operator has a lower precedence than the and and or operators.
False
2
The comparison operators are applied after addition but before assignment.
True
3
Conditional iteration requires that a condition be tested within the loop to determine whether the loop should continue.
True
4
"A"
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
The augmented assignment operations have a higher precedence than the standard assignment operation.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
When the step argument is a negative number, the range function generates a sequence of numbers from the first argument down to the second argument plus 1.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
A condition expresses a hypothesis about the state of its world at that point in time.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
There are two types of loops-those that repeat an action a predefined number of times (definite iteration) and those that perform the action until the program determines that it needs to stop (indefinite iteration).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
For the most part, off-by-one errors result when the programmer incorrectly specifies the lower bound of the loop.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
The or operator returns True if and only if both of its operands are true, and returns False otherwise.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
Loop statements allow a computer to make choices.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
Simple Boolean expressions consist of the Boolean values True or False, variables bound to those values, function calls that return Boolean values, or comparisons.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
The assignment symbol can be combined with the arithmetic and concatenation operators to provide augmented assignment operations.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
The statements in the loop body need not be indented and aligned in the same column.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
4 != 4 evaluates to True.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The if-else statement is the most common type of selection statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
The not operator expects a single operand and returns its logical negation, True, if it's false, and False if it's true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
The simplest form of selection is the if-else statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
The Boolean data type is named for the twentieth-century British mathematician George Boole.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
In Python, = means equals, whereas == means assignment.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
Some computer scientists argue that a while True loop with a delayed exit violates the spirit of the while loop.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Given the following statement: "%4d" % var1, which of the following is accurate?

A) The variable var1 must be an integer value.
B) The variable var1 must be a string value.
C) The variable var1 will be in octal format.
D) The variable var1 will be formatted regardless of type.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
In evaluating a loop, you find the following statement: "value += 1". What happens to the value variable upon each iteration of the loop?

A) The variable is reset to an int type, with a value of 1.
B) The variable's value is changed to a positive value.
C) The variable is increased by 1 each iteration through the loop.
D) The variable is incremented by itself.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
What statement should you use to print the value of total with a precision of 5 digits?

A) print("The total is %5." % total)
B) print("The total is %0.5d" % total)
C) print("The total is %f" % float(total, 5))
D) print("The total is %0.5f" % total)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
Although the while loop can be complicated to write correctly, it is possible to simplify its structure and thus improve its readability.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
What are the two different types of loops that are used within the Python language? (Choose two.)

A) predetermined looping
B) definite iteration
C) infinite cycling
D) indefinite iteration
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
What comparison operator is used to test whether an expression does NOT equal another expression?

A) -=
B) !=
C) /=
D) _=
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
What is the minimum number of spaces that should be used to create an indented statement?

A) one space
B) two spaces
C) three spaces
D) four spaces
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
In a conditional iteration loop, such as a while loop, what is a sentinel value?

A) A sentinel value is a user-provided input value that proceeds to the next loop.
B) A sentinel value is a user-provided input value that changes the structure of the loop.
C) A sentinel value is a special value provided by the user to terminate the loop.
D) A sentinel value is a special value provided by the user to restart the loop.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
If A is True, what will the statement "not A" return?

A) Undefined
B) True
C) False
D) BooleanError
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
What is a one-way selection statement in the context of Python?

A) It is a single if statement without a corresponding else statement used to test a condition and run statements, then proceed to the next statement.
B) It is a single if-else statement block that is used to test a condition and run statements, as well as provide a default path for execution.
C) It is a switch statement block that is used to direct the flow of data based on a single condition.
D) It is an if statement that tests no conditions, but provides a block for execution.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
You are running a Python script and suspect that the script has entered an infinite loop. What key combination can you use to halt the loop?

A) CTRL + Esc
B) CTRL + c
C) Alt + b
D) CTRL + Break
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
What character is used as the format operator when formatting output?

A) ^
B) $
C) %
D) @
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
When using the range function, what effect does the specification of a third argument have?

A) The third argument is used as the starting point for the range function.
B) The third argument specifies a step value to be used in the range.
C) The third argument declares an exponential value the numbers will be raised to.
D) The third argument is simply included in the sequence, assuming it wasn't already in the range.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
The while loop is also called a sentinel-control loop, because its condition is tested at the top of the loop.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Inside of a loop, after a termination condition has been met, what statement can be used to cause an exit from the loop and execute the remainder of the script?

A) exit
B) break
C) quit
D) halt
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
The while loop is also known as what kind of a loop?

A) infinite loop
B) operational loop
C) user-control loop
D) entry-control loop
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
A while loop can be used for a count-controlled loop.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
An off-by-one error is an example of what type of error in programming?

A) logic error
B) syntax error
C) type error
D) input error
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
The statements within a while loop can execute one or more times.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
What scenario would it make logical sense to use a multi-way selection statement for?

A) You need to convert numeric grades to letter grades.
B) You need to test if the value of A is larger than B.
C) You need to determine if a number is positive or negative.
D) You need to test if a variable is True or False.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Assuming that the value of x is 4, and the value of y is 6, what is the value of the following expression? (x - y)**2 > y

A) True
B) False
C) Undefined
D) TypeError
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
The use of +=, -=, and *= are all examples of what type of operators?

A) protracted assignment operators
B) augmented assignment operators
C) extended arithmetic operators
D) overloaded mathematic operators
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
What is NOT a Boolean or logical operator used in the Python language?

A) and
B) or
C) not
D) xor
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
In programming, what is a prototype?

A) It is a rough draft of a program.
B) It is a program in final stages of development.
C) It is a program statement that builds a module.
D) It is a production-ready program.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
In general terms, what does a selection statement do?

A) It forces a computer to favor one value over another.
B) It allows a computer to make choices based on test conditions.
C) It allows a computer to select the values that are most economical.
D) It allows a computer to selectively execute based on processing cost.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
What function call will generate a random number in the range of 1 through 6 using the random module?

A) random.randnum(1, 6)
B) random.randint(range(1-6))
C) random.randint(1, 6)
D) random.random(1, 6)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
What statement regarding precedence of operators is accurate?

A) The assignment operator (=) is higher in precedence than exponentiation (**).
B) The logical conjunction (and) is higher in precedence than the logical negation (not).
C) The comparison operators (==, !=, , =) are higher in precedence than the assignment operator (=).
D) The addition and subtraction operators (+, -) are lower in precedence than the logical conjunction operator (and).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
What part of the loop comprises the statements to be executed?

A) The loop header.
B) The loop body.
C) The loop end.
D) The loop tail.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
What is a count controlled loop?

A) It is a loop that counts iterations until a sentinel value is received.
B) It is a loop that continues based on a certain time interval.
C) It is a loop that prints out a count of values for the user.
D) It is a loop that counts through a range of numbers to control when the loop ends.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.