Unit 4 Flashcards

Branching

1
Q

4.1 - If-Else Branches (General)

What is a branch?

A

a sequence of statements only executed under a certain condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

4.1 - If-Else Branches (General)

What does an if/else statement do?

A

if a statement is true, perform x command
else / otherwise, perform y command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

4.2 - Detecting Equal Values with Branches

How do you check if two values are and are not equal?

using x and y, code format

use x = y

A

if x == y
if x != y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

4.2 - Detecting Equal Values with Branches

What does elif do?

A

acts as a secondary if statement with less imporance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

4.2 - Detecting Equal Values with Branches

What is Boolean Logic?

or just a Boolean value

A

a binary system of representing information (true/false system)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

4.3 - Detecting Ranges with Branches (General)

How do you check if a value is within a range?

x between y and z, in code format

A

if y < x < z or
if y > x and x < z

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

4.4 - Detecting Ranges with Branches

What are relational operators?

definition & symbols

A

operators used for comparing values
< > <= >= = and ==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

4.4 - Detecting Ranges with Branches

What is operator chaining?

just give an example, x y and z

A

x < y < z

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

4.5 - Detecting Ranges Using Logical Operators

What is a logical operator?

A

an operator which conforms to Boolean logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

4.5 - Detecting Ranges Using Logical Operators

What are the three logical operators?

A

and true if both operands are true
or true if either operand is true
not true if opposite opperand is false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

4.6 - Detecting Ranges with Gaps

What is a fall-through?

A

a programming problem where improper ranges lead to values “falling through” gaps

x < 10
x > 10
but what if x == 10?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

4.7 - Detecting Multipe Features with Branches

What is a nested if/else statement?

A

an if/else statement within another if/else statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

4.8 - Comparing Data Types and Common Errors

Why should you avoid using equality operators with floating-point numbers?

A

equality operators might inaccurately represent the floats

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

4.9 - Membership and Identity Operators

What are the two membership operators and what do they do?

A

in and not in
determines if left operand is featured in right operand (container)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

4.9 - Membership and Identity Operators

What are the two identity operators and what do they do?

A

is and is not
checks if two operands are bound to the same object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

4.10 - Order of Evaluation

What is the order of evaluation/precedence rules?

A
  1. parenthesis
  2. arithmetic operators
  3. relational operators and membership operators
  4. not
  5. and
  6. or

2 → * / % + -
3 → < <= > >= == != and in not in
4-6 → logical operators

17
Q

4.11 - Code Blocks and Indentation

How many spaces equal one tab?

A

4 spaces → 1 tab

18
Q

4.12 - Conditional Expressions

What is a ternary operation?

A

a three-part operation
x if y else z

if y is true, then x… otherwise z

it’s better to avoid these