Python quiz 3
In Python the ________ symbol is used as the not-equal-to operator. Answers: == <> <= !=
!=
In Python the ________ symbol is used as the equality operator. <> <= == !=
==
How can the effect of the following program segment best be described? if x > y: z = x elif x < y: z = y else: z = 0 The smaller of x and y is stored in z. The larger of x and y is stored in z. The larger of x and y is stored in z, unless x and y are equal, in which case z is assigned 0. The larger of x and y is stored in z, unless x and y are not equal, in which case z is assigned 0. None of these
The larger of x and y is stored in z, unless x and y are equal, in which case z is assigned 0.
When using the ________ logical operator, both subexpressions must be true for the compound expression to be true. or not either or or and and
and
Multiple Boolean expressions can be combined by using a logical operator to create ________ expressions. logical mathematical sequential compound
compound
A(n) ________ structure is a logical design that controls the order in which a set of statements execute. control iteration function sequence
control
The decision structure that has two possible paths of execution is known as single alternative two alternative dual alternative double alternative
dual alternative
Python allows you to compare strings, but it is not case sensitive.
false
Python uses the same symbols for the assignment operator as for the equality operator.
false
Short -circuit evaluation is only performed with the not operator.
false
The Python language is not sensitive to block structuring of code.
false
The not operator is a unary operator which must be used in a compound expression.
false
What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y and z > x 5 False True 8
false
What is the result of the following Boolean expression, given that x = 5, y = 3, and z= 8? not (x < y or z > x) and y < z False 8 True 5
false
Which code segment correctly expresses the following statement? For all employees under the age of 25 or over the age of 50, bonus is increased by 5%. Assume that the variables age and bonus have been declared and initialized and are accessible by the code. if age < 25 and age > 50: bonus = bonus * 1.05 if age <= 25 or age => 50: bonus = bonus * 1.05 if age < 25 or age > 50: bonus = bonus * 1.05 if age > 25 or age < 50: bonus = bonus * 1.05
if age < 25 or age > 50: bonus = bonus * 1.05
Which of the following is the correct if clause to determine whether choice is anything other than 10? if choice <> 10: if choice != 10 if choice != 10: if not(choice < 10 and choice > 10):
if choice != 10:
Write an if statement that prints the message 'The number is valid' if the variable, number, is within the range 0 through 100 inclusive. if number >= 0 or number <= 100: print('The number is valid') if number >= 0 print('The number is valid') number <= 100: print('The number is valid') if number >= 0 and number <= 100: print('The number is valid') All of these will work
if number >= 0 and number <= 100: print('The number is valid')
Which of the following is the correct if clause to determine whether y is in the range 10 through 50, inclusive? if 10 < y or y > 50: if y >= 10 or y <= 50: if 10 > y and y < 50: if y >= 10 and y <= 50:
if y >= 10 and y <= 50:
Write an if statement that assigns 0 to the variable x and 1 to the variable y if the variable z is equals to 20. if z = 20: x = 0 y = 1 if z == 0: x = 20 y = 1 if z == 20: x = 0 y = 1 if z == 1: x = 0 y = 20
if z == 20: x = 0 y = 1
When using the ________ logical operator, one or both of the subexpressions must be true for the compound expression to be true.
or
Which logical operators perform short-circuit evaluation? or, and and, or, not or, not not, and
or, and
An action in a single alternative decision structure is performed only when the condition is true.
true
Decision structures are also known as selection structures.
true
Expressions that are tested by the if statement are called Boolean expressions.
true
Nested decision statements are one way to test more than one condition.
true
The if statement causes one or more statements to execute only when a Boolean expression is true.
true
To place an entire block of statements within an if statement, you must indent the block.
true
What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y or z > x 8 True 5 False
true
A Boolean variable can reference one of two values which are True or False yes or no Y or N T or F
true or false
What does the following expression mean? x <= y x is less than y x is less than or equal to y x is greater than or equal to y x is greater than y
x is less than or equal to y