True/False Indicate whether the
statement is true or false.
|
|
|
1.
|
The Python language is not sensitive to block structuring of code.
|
|
|
2.
|
The if statement causes one or more statements
to execute only when a Boolean expression is true.
|
|
|
3.
|
Python allows you to compare strings, but it is not case sensitive.
|
|
|
4.
|
Nested decision statements are one way to test more than one condition.
|
|
|
5.
|
Python uses the same symbols for the assignment operator as for the equality
operator.
|
|
|
6.
|
The not operator is a unary operator which
must be used in a compound expression.
|
|
|
7.
|
Short -circuit evaluation is only performed with the not operator.
|
|
|
8.
|
Expressions that are tested by the if
statement are called Boolean expressions.
|
|
|
9.
|
Decision structures are also known as selection structures.
|
|
|
10.
|
An action in a single alternative decision structure is performed only when the
condition is true.
|
|
|
11.
|
The following statement will check to see if the turtle's pen color is
'green': if turtle.pencolor() = 'green'
|
|
|
12.
|
The following code snippet will change the turtle's pen size to 4 if it is presently less than 4: if turtle.pensize() < 4:
turtle.pensize(4)
|
Multiple Choice Identify the
choice that best completes the statement or answers the question.
|
|
|
13.
|
A(n) __________ structure is a logical design that controls the order in which a
set of statements execute.
a. | function | c. | sequence | b. | control | d. | iteration |
|
|
|
14.
|
The decision structure that has two possible paths of execution is known
as
a. | single alternative | c. | dual alternative | b. | double alternative | d. | two alternative |
|
|
|
15.
|
Multiple Boolean expressions can be combined by using a logical operator to
create __________ expressions.
a. | sequential | c. | compound | b. | logical | d. | mathematical |
|
|
|
16.
|
When using the __________ logical operator, one or both of the subexpressions
must be true for the compound expression to be true.
|
|
|
17.
|
Which logical operators perform short-circuit evaluation?
a. | or, not | c. | or, and | b. | not, and | d. | and, or, not |
|
|
|
18.
|
Which of the following is the correct if
clause to determine whether y is in the range 10 through 50, inclusive?
a. | if 10 < y or y > 50: | c. | if y >= 10 and y <= 50: | b. | if 10 > y and y <
50: | d. | if y >= 10 or y <= 50: |
|
|
|
19.
|
A Boolean variable can reference one of two values which are
a. | yes or no | c. | T or F | b. | True or
False | d. | Y or N |
|
|
|
20.
|
What is the result of the following Boolean expression, given that x = 5, y = 3, and z
= 8? x < y or z >
x
|
|
|
21.
|
What is the result of the following Boolean expression, given that x = 5, y = 3, and z
= 8? x < y and z >
x
|
|
|
22.
|
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
|
|
|
23.
|
What does the following expression mean? x <= y
a. | x is less than y | b. | x is less than or equal to y | c. | x is greater than
y | d. | x is greater than or equal to
y |
|
|
|
24.
|
Which of the following is the correct if
clause to determine whether choice is anything other than 10?
a. | if choice != 10: | b. | if choice != 10 | c. | if choice <>
10: | d. | if not(choice < 10 and choice >
10): |
|
|
|
25.
|
When using the __________ logical operator, both subexpressions must be true for
the compound expression to be true.
a. | or | c. | not | b. | and | d. | either or or and |
|
|
|
26.
|
In Python the __________ symbol is used as the not-equal-to operator.
|
|
|
27.
|
In Python the __________ symbol is used as the equality operator.
|
|
|
28.
|
Which of the following will hide the turtle if it is visible?
a. | if turtle.isvisible(): turtle.invisible() | b. | if turtle.isvisible turtle.hideturtle() | c. | turtle.isvisible(): turtle.hide() | d. | if
turtle.isvisible():
turtle.hideturtle() |
|
|
|
29.
|
Which of the following will determine if the turtle's pen is up and will
change it to down if that is the case?
a. | if turtle.isup(): turtle.isdown() | b. | if turtle.isdown
turtle.penup() | c. | if
not(turtle.isdown()):
turtle.pendown() | d. | if
not(turtle.penup())
turtle.penup() |
|
Completion Complete each
statement.
|
|
|
30.
|
The ___________ statement is used to create a decision structure.
|
|
|
31.
|
In flowcharting, the __________ symbol is used to represent a Boolean
expression.
|
|
|
32.
|
A(n) __________ decision structure provides only one alternative path of
execution.
|
|
|
33.
|
In a decision structure, the action is ___________ executed because it is
performed only when a specific condition is true.
|
|
|
34.
|
A(n) __________ operator determines whether a specific relationship exists
between two values.
|
|
|
35.
|
A(n) __________ statement will execute one block of statements if its condition
is true or another block if its condition is false.
|
|
|
36.
|
Python provides a special version of a decision structure known as the
__________ statement, which makes the logic of the nested decision structure simpler to write.
|
|
|
37.
|
The logical __________ operator reverses the truth of a Boolean
expression.
|
|
|
38.
|
Boolean variables are commonly used as __________ to indicate whether a specific
condition exists.
|
|
|
39.
|
A(n) ___________ expression is made up of two or more Boolean
expressions.
|
|
|
40.
|
The turtle.isdown() function returns
___________ if the turtle's pen is down.
|
Code
|
|
|
41.
|
Write a program that prompts the user to enter a number within the range of 1
through 10. The program should display the Roman numeral version of that number. If the number
is outside the range of 1 through 10, the program should display an error message.
|
|
|
42.
|
The area of a rectangle is the rectangle’s length times its width. Write a
program that asks for the length and width of two rectangles. The program should tell the user
which rectangle has the greater area, or if the areas are the same
|
|
|
43.
|
Scientists measure an object’s mass in kilograms and its weight in
newtons. If you know the amount of mass of an object in kilograms, you can calculate its weight in
newtons with the following formula:
weight = mass x 9.8
Write a program that
asks the user to enter an object’s mass, and then calculates its weight and print it . If
the object weighs more than 1,000 newtons, display a message indicating that it is too heavy. If
the object weighs less than 10 newtons, display a message indicating that it is too light.
|