Programming HW 4
In Python the ________ symbol is used as the not-equal-to 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 larger of x and y is stored in z, unless x and y are equal, in which case z is assigned 0.
A Boolean variable can reference one of two values which are
True or False
Which of the following is the correct if clause to determine whether choice is anything other than 10?
if choice != 10:
In Python the ________ symbol is used as the equality operator.
==
Decision structures are also known as selection structures.
True
What does the following expression mean?x <= y
x is less than or equal to y
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
An action in a single alternative decision structure is performed only when the condition is true.
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
Multiple Boolean expressions can be combined by using a logical operator to create ________ expressions.
compound
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
What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8?x < y and z > x
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
What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8?x < y or z > x
True
When using the ________ logical operator, both subexpressions must be true for the compound expression to be true.
and
A(n) ________ structure is a logical design that controls the order in which a set of statements execute.
control
The decision structure that has two possible paths of execution is known as
dual alternative
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.
f z == 20: x = 0 y = 1
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
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 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 y >= 10 and y <= 50:
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