[go: up one dir, main page]

0% found this document useful (0 votes)
28 views3 pages

Chapter 3

This document discusses decision structures and Boolean logic. It explains that an if-else statement can determine whether certain conditions are true, and display different messages depending on if the conditions are true or false. It also contains review questions about decision structures, Boolean operators like and/or/not, and flags.

Uploaded by

apap.004589
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

Chapter 3

This document discusses decision structures and Boolean logic. It explains that an if-else statement can determine whether certain conditions are true, and display different messages depending on if the conditions are true or false. It also contains review questions about decision structures, Boolean operators like and/or/not, and flags.

Uploaded by

apap.004589
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

170 Chapter 3 Decision Structures and Boolean Logic

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

3. A(n) __________ expression has a value of either True or False.


a. binary
b. decision
c. unconditional
d. Boolean
4. The symbols >, <, and == are all __________ operators.
a. relational
b. logical
c. conditional
d. ternary
5. A(n) _________ structure tests a condition and then takes one path if the condition is
true, or another path if the condition is false.
a. if statement
b. single alternative decision
c. dual alternative decision
d. sequence
6. You use a(n) __________ statement to write a single alternative decision structure.
a. test-jump
b. if
c. if-else
d. if-call
7. You use a(n) __________ statement to write a dual alternative decision structure.
a. test-jump
b. if
c. if-else
d. if-call
8. and, or, and not are __________ operators.
a. relational
b. logical
c. conditional
d. ternary
9. A compound Boolean expression created with the __________ operator is true only if
both of its subexpressions are true.
a. and
b. or
c. not
d. both
10. A compound Boolean expression created with the _________ operator is true if either
of its subexpressions is true.
a. and
b. or
c. not
d. either
172 Chapter 3 Decision Structures and Boolean Logic

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.

You might also like