1/33
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
control structure
a logical design that controls the order in which a set of statements execute
sequence structure
a set of statements that execute in the order they appear
single-alternative decision
tests a condition and then takes one path if the condition is true or another path if the condition is false
if clause
begins with the word if, followed by a condition and a colon
Boolean expressions
expressions tested by the if statement
What operator is typically used in Boolean expressions?
relational
relational operator
determines whether a specific relationship exists between two values
>=
greater than or equal to
<=
less than or equal to
==
equal to
!=
equal to
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
True or false: the if and else clauses within an if-else statement do not have to be aligned
false
True or false: relationship operators can be applied to strings
true
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
True or false: string comparisons are case sensitive
true
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
True or false: shorter strings are considered greater than longer strings
false
When is nesting decision structures necessary?
when a program needs to test more than one condition
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
if-elif-else statement
allows a program to execute different blocks of code based on specific conditions
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.
logical operators
used to create complex Boolean expressions
ex: and, or, not
and
both subexpressions must be true for the compound expression to be true
or
one or both subexpressions must be true for the compound expression to be true
not
returns false if applied to a true expression and true if applied to a false expression
short-circuit evaluation
a logical expression is evaluated from left to right, and evaluation stops as soon as the final outcome is mathematically guaranteed
any()
true if any element in an iterable is true
all()
true if all elements in an iterable are true
ternary operator
a concise way to execute simple if-else statements in a single line
ternary operator syntax
a if condition else b
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"
bool data type
represents a binary value of either true or false
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.