Chapter 4 - Decision Structures & Boolean Logic

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/33

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 6:08 PM on 6/20/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

34 Terms

1
New cards

control structure

a logical design that controls the order in which a set of statements execute

2
New cards

sequence structure

a set of statements that execute in the order they appear

3
New cards

single-alternative decision

tests a condition and then takes one path if the condition is true or another path if the condition is false

4
New cards

if clause

begins with the word if, followed by a condition and a colon

5
New cards

Boolean expressions

expressions tested by the if statement

6
New cards

What operator is typically used in Boolean expressions?

relational

7
New cards

relational operator

determines whether a specific relationship exists between two values

8
New cards

>=

greater than or equal to

9
New cards

<=

less than or equal to

10
New cards

==

equal to

11
New cards

!=

equal to

12
New cards

dual alternative decision structure

evaluates a condition and provides exactly two mutually exclusive paths of execution:

  • true → the if block is executed, and the else block is bypassed

  • false → the if block is bypassed, and the else block is executed

13
New cards

True or false: the if and else clauses within an if-else statement do not have to be aligned

false

14
New cards

True or false: relationship operators can be applied to strings

true

15
New cards

What is the output for this code?

name1 = "Mary"
name2 = "Mark"

if name1 == name2:
	print("The names are the same")
else:
	print("The names are NOT the same")

The names are NOT the same

16
New cards

True or false: string comparisons are case sensitive

true

17
New cards

How does a program compare characters?

by comparing the codes for the characters

  • the farther in the alphabet a character is, the greater its code

18
New cards

True or false: shorter strings are considered greater than longer strings

false

19
New cards

When is nesting decision structures necessary?

when a program needs to test more than one condition

20
New cards

How should nested decision structures be formatted?

each else clause should be aligned with its matching if clause, and the statements within each block must be consistently indented

21
New cards

if-elif-else statement

allows a program to execute different blocks of code based on specific conditions

22
New cards

What is the output for this code?

score = 72

if score < 60:
	print("Your grade is F.")
elif score < 70:
	print("Your grade is D.")
elif score < 80:
	print("Your grade is C.")
elif score < 90: 
	print("Your grade is B.")
else:
	print("Your grade is A.")

Your grade is C.

23
New cards

logical operators

used to create complex Boolean expressions

ex: and, or, not

24
New cards

and

both subexpressions must be true for the compound expression to be true

25
New cards

or

one or both subexpressions must be true for the compound expression to be true

26
New cards

not

returns false if applied to a true expression and true if applied to a false expression

27
New cards

short-circuit evaluation

a logical expression is evaluated from left to right, and evaluation stops as soon as the final outcome is mathematically guaranteed

28
New cards

any()

true if any element in an iterable is true

29
New cards

all()

true if all elements in an iterable are true

30
New cards

ternary operator

a concise way to execute simple if-else statements in a single line

31
New cards

ternary operator syntax

a if condition else b

32
New cards

What is the output for this code?

x = 10
result = "Greater than 5" if x > 5 else "Less than or equal to 5"
print(result)

"Greater than 5"

33
New cards

bool data type

represents a binary value of either true or false

34
New cards

What is the output for this code if the user inputs 63,429?

sales = float(input())

if sales >= 50000.00:
	sales_quota_met = True
else:
	sales_quota_met = False

if sales_quota_met:
	print("You have met your sales quota.")
else:
	print("You have not met your sales quota.")

You have met your sales quota.