BvP 2 - Chapter 3 - Selection

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/38

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

39 Terms

1
New cards

What is a conditional statement?

A statement that allows decisions in code based on conditions.

2
New cards

Syntax of an if statement

A way to execute code only when a condition is true.

3
New cards

Relational operators

Symbols used to compare values, like greater than or equal to.

4
New cards

Difference between assignment and equality testing

Assignment sets a value; equality checks if values are the same.

5
New cards

Example: Check if a number is odd

Test if the remainder when divided by 2 is not zero.

6
New cards

How to compare strings

Use equality or inequality operators to check if strings are the same or different.

7
New cards

What is lexicographical order?

String comparison based on alphabetical or ASCII order.

8
New cards

Operations for testing substrings

Check if a substring exists within a string using logical operators.

9
New cards

What is a nested branch?

A conditional statement placed inside another conditional statement.

10
New cards

Syntax of elif

Used to check additional conditions after the first condition is false.

11
New cards

What is a match/case statement?

A way to handle multiple cases in a cleaner format introduced in Python 3.10.

12
New cards

Boolean operators

Logical operators like and, or, and not used to combine conditions.

13
New cards

Use of and

Both conditions must be true for the result to be true.

14
New cards

Use of or

At least one of the conditions must be true for the result to be true.

15
New cards

Use of not

Inverts the truth value of a condition.

16
New cards

Check if two floats have the same sign

Test if both numbers are either positive or negative.

17
New cards

Input validation for age

Ensure the age is within a specific range before proceeding.

18
New cards

What to do in nested branching?

Test specific conditions first, then general conditions.

19
New cards

Common mistake in multiple conditions

Forgetting to use elif, leading to unnecessary checks.

20
New cards

Purpose of relational operators

To compare two values and return a true or false result.

21
New cards

Difference between greater than and greater than or equal

One includes equality, while the other excludes it.

22
New cards

Purpose of lexicographical order

To compare strings in a way similar to dictionary order.

23
New cards

How to test if a string ends with a specific substring

Use substring testing to check for a specific ending.

24
New cards

Difference between uppercase and lowercase in comparison

Uppercase letters are evaluated as smaller than lowercase.

25
New cards

Purpose of nested branches

To handle complex decision trees by embedding conditions.

26
New cards

Alternative to nested branches

Use elif to simplify and flatten the decision structure.

27
New cards

Example of a special case in conditions

Handle exceptions or outliers before general cases.

28
New cards

Key advantage of match/case

More readable and structured for multiple conditions.

29
New cards

What happens if no match in a case statement?

The default action is taken if defined.

30
New cards

Difference between and and or

And requires all conditions to be true, or requires at least one true.

31
New cards

Purpose of not

To reverse or negate the condition being checked.

32
New cards

Example of a boolean variable

A variable that holds either true or false.

33
New cards

When to use range checking

To verify if a value falls between two limits.

34
New cards

How to simplify logic with not

Use not to reduce the complexity of multiple checks.

35
New cards

What is equality testing for strings?

Checking if two strings have identical content.

36
New cards

Example of a multiway branching

Using multiple elif statements to test various conditions.

37
New cards

Key to writing efficient branching

Place the most likely conditions first to minimize checks.

38
New cards

Testing for case sensitivity

Ensure comparisons account for the exact casing of strings.

39
New cards

Common mistake in boolean logic

Confusing and with or, leading to incorrect result