Chapter 3
Chapter 3
The last thing to do is determine whether the turtle hit the target. If the turtle is inside the
target, all of the following will be true:
• The turtle’s X coordinate will be greater than or equal to TARGET_LLEFT_X
• The turtle’s X coordinate will be less than or equal to TARGET_LLEFT_X + TARGET_
WIDTH
• The turtle’s Y coordinate will be greater than or equal to TARGET_LLEFT_Y
• The turtle’s Y coordinate will be less than or equal to TARGET_LLEFT_Y + TARGET_
WIDTH
The if-else statement in lines 57 through 63 determines whether all of these condi-
tions are true. If they are true, the message 'Target hit!' is displayed in line 61.
Otherwise, the message 'You missed the target.' is displayed in line 63.
Assassastasag
Checkpoint
3.22 How do you get the turtle’s X and Y coordinates?
3.23 How would you determine whether the turtle’s pen is up?
3.24 How do you get the turtle’s current heading?
3.25 How do you determine whether the turtle is visible?
3.26 How do you determine the turtle’s pen color? How do you determine the current
fill color? How do you determine the current background color of the turtle’s
graphics window?
3.27 How do you determine the current pen size?
3.28 How do you determine the turtle’s current animation speed?
Review Questions
Multiple Choice
1. A __________ structure can execute a set of statements only under certain
circumstances.
a. sequence
b. circumstantial
c. decision
d. Boolean
2. A __________ structure provides one alternative path of execution.
a. sequence
b. single alternative decision
c. one path alternative
d. single execution decision
Review Questions 171
11. The ___________ operator takes a Boolean expression as its operand and reverses its
logical value.
a. and
b. or
c. not
d. either
12. A ___________ is a Boolean variable that signals when some condition exists in the
program.
a. flag
b. signal
c. sentinel
d. siren
True or False
1. You can write any program using only sequence structures. False
2. A program can be made of only one type of control structure. You cannot combine
structures. False
3. A single alternative decision structure tests a condition and then takes one path if the
condition is true, or another path if the condition is false. False
4. A decision structure can be nested inside another decision structure. True
5. A compound Boolean expression created with the and operator is true only when both
subexpressions are true. True
Short Answer
1. Explain what is meant by the term “conditionally executed.”
2. Explain how a single alternative decision structure and a dual alternative decision
structure differ.
3. Briefly describe how the and operator works.
4. Briefly describe how the or operator works.
5. When determining whether a number is outside a range, which logical operator is it
best to use?
6. What is a flag and how does seats
it work?
Algorithm Workbench
1. Write an if statement that assigns 20 to the variable y, and assigns 40 to the variable z
if the variable x is greater than 100.
2. Write an if statement that assigns 10 to the variable b, and 50 to the variable c if the
variable a is equal to 100.
3. Write an if-else statement that assigns 0 to the variable b if the variable a is less
than 10. Otherwise, it should assign 99 to the variable b.