Python Chapter 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

A logical design that controls the order in which a set of statements execute is called a _____

control structure

relational operator

determines whether a specific relationship exists between two values

value of (true or true)

true

A(n) ________ expression has a value of either true or false.

Boolean

String comparisons are case sensitive.

True

value of (false and false)

false

value of (false and true)

false

value of (false or false)

false

value of (false or true)

true

not equal to

!=

logical operators

(and) & (or) which allow you to connect multiple Boolean expressions to create a compound expression.

Less than

<

Less than or equal to

<=

equal to

==

Greater than

>

Greater than or equal to

>=

When a program compares characters, it actually compares the ________ codes.

ASCII

Briefly describe how the and operator works.

An expression formed by the "and" operator is true only when both the 'first' and 'second' sub expressions are true.

Briefly describe how the or operator works.

An expression formed by the "or" operator will be true when at least one of the subexpressions is evaluated as true.

A program can be made of only one type of control structure. You cannot combine structures.

False

It is best to use the or operator when determining whether a number is inside a range.

False

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 (dual alternative)

A compound Boolean expression created with the and operator is true only when both subexpressions are true.

True

A compound Boolean expression created with the or operator is true only when one subexpression is true.

True

In addition to determining whether strings are equal or not equal, you can also determine whether one string is greater than or less than another string.

True

block

a set of statements that belong together as a group

A compound Boolean expression created with the ________ operator is true only if both of its subexpressions are true

and

When determining whether a number is inside a range, which logical operator is it best to use?

and

decision structure

another term for the selection structure

Boolean variable

can reference one of two values: True or False. commonly used as flags, which indicate whether a specific condition exists.

What are decision structures and sequence structures?

decision structures process blocks of statements when the conditions which control those blocks are evaluated as true. sequence structures process statements in the order in which they are written in the program.

A(n) ________ structure tests a condition and then takes one path if the condition is true, or another path if the condition is false.

dual alternative decision

value of (not true)

false

value of (true and false)

false

A _______ is a Boolean variable that signals when some condition exists in the program.

flag

Boolean variables are commonly used as _______ and if it is set to _______ it indicates the condition does not exist.

flags, False

dual alternative decision structure

has two possible paths of execution

Give an example of a nested if-else statement.

if a == 20: b = 2 else: b = 4

if-else statement structure

if condition: statement statement etc. else: statement statement etc.

Write an if statement that assigns 0.2 to commisionRate if sales is greater than or equal to 10000.

if sales >= 10000: commisionRate = 0.2

short circuit evaluation

if the expression on the left side of the and operator is false, the expression on the right side will not be checked.

Write an if statement that assigns 0 to x if y is equal to 20.

if y == 20: x = 0

The ______ statement causes one or more statements to execute only when a Boolean expression is ________

if, true

You use a(n) __________ statement to write a dual alternative decision structure.

if-else

Boolean Expression

in programming, an expression that evaluates to True or False.

and, or, and not are _______ operators

logical

control structure

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

guidelines for if-else statement

make sure the if clause and else clause are aligned. AND the if clause and else clause are each followed by a block of statements. Make sure the statements in the block are consistently indented.

The logical _______________ operator reverses the truth of a Boolean expression.

not

and

operator that connects two Boolean expressions into one compound expression. both must be true for the compound expression to be true.

or

operator that connects two Boolean expressions into one compound expression. one or both subexpressions must be true for the compound expression to be true. It is only necessary for one of the subexpressions to be true, and it does not matter which.

A compound Boolean expression created with the _______ operator is true if either of its subexpressions is true

or

single alternative decision structure

provides only one alternative path of execution

What is short-circuit evaluation?

refers to the way the computer evaluates two subexpressions, where if the expression on the left of the and operator is true then the expression on the right side will not be checked.

sequence structure

set of statements that execute in the order that they appear

If the expression on the left side of the and operator is false, the expression on the right side will not be checked. This is called as ________

short-circuit evaluation

if-elif-else statement

special version of a decision structure

comparing strings

tests whether two strings are equal to one another. allows you to create decision structures that test the value of a string.

value of (not false)

true

value of (true and true)

true

value of (true or false)

true

A diamond symbol in a flowchart indicates:

true/false condition

not

unary operator that works with only one operand and reverses the truth of the operand. must be a boolean expression.

if statement

used to create a decision structure, which allows a program to have more than one path of execution. causes one or more statements to execute only when a Boolean expression is true.

nested decision structure

used to test more than one condition

What types of relationships between values can you test with relational operators?

values that determine true and false

if-else statement

will execute one block of statements if its condition is true, or another block if its condition is false


Conjuntos de estudio relacionados

Review Questions chapter 16 A/P II

View Set

Contemporary Retail Management Chapter 16: Store Layout, Design, and Visual Merchandising

View Set

𝘊𝘏𝘈𝘗𝘛𝘌𝘙 8 ~ 𝘉𝘜𝘚𝘐𝘕𝘌𝘚𝘚

View Set

Performing Hand Hygiene Using Soap and Water Quiz

View Set