COMP Quiz 4 Study Set

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

1/19

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.

20 Terms

1
New cards

What does the print() function do in Python?

It displays output to the screen.

2
New cards

What is a variable?

A named storage location for data that can change during program execution.

3
New cards

What is the difference between = and == in Python?

= assigns a value, while == checks equality.

4
New cards

What does the input() function do?

It lets the user type input, which is read as a string.

5
New cards

What is the basic syntax for an if-else statement that executes different code based on a condition?

if condition:\n # code executes if condition is True\nelse:\n # code executes if condition is False\nKey point: Only one branch executes.

6
New cards

How do you trace through code with conditionals to find final variable values?

Start with initial values, evaluate conditions in order, execute only the block that's true, skip the rest, continue after conditionals, and update variables step by step.

7
New cards

What's the difference between an if-elif-else chain and multiple separate if statements?

An if-elif-else chain only runs the first true condition and then exits. Multiple if statements check independently, so more than one block can run.

8
New cards

What are the key comparison operators and how do they evaluate?

== equal to, != not equal to, < less than, <= less than or equal to, > greater than, >= greater than or equal to. They return True or False.

9
New cards

In what order are operators evaluated in expressions like x + y < z * 2?

Parentheses → Multiplication/Division → Addition/Subtraction → Comparisons → Logical operators. Example: (x + y) < (z * 2).

10
New cards

How do nested if statements work, and what conditions must be true for inner blocks to execute?

The outer condition must be True, and the inner condition must also be True for the inner block to run.

11
New cards

How do you check if a value exists in a list, dictionary, or string?

Use membership operators: value in container (True if found), value not in container (True if not found).

12
New cards

How do you create conditions that check if a value falls within a specific range?

Use two conditions with and. Example: if x >= 10 and x <= 20:

13
New cards

When does variable assignment inside conditional blocks take effect?

Only when that block runs. If the condition is False, the assignment is skipped.

14
New cards

What are the essential indentation rules for conditionals in Python?

Code in if/else must be indented, all code at the same level has the same indent, else lines up with if, and code after conditionals goes back to the left margin.

15
New cards

How do you determine which branch of a multi-way conditional will execute?

In an if-elif-else chain, Python checks from top to bottom. The first True condition executes, and the rest are skipped. If none are True, the else block runs.

16
New cards

What's the strategy for creating complex conditions with multiple requirements?

Use compound logic: and = all must be true, or = any can be true, not = reverses condition. Parentheses group conditions for clarity.

17
New cards

What's the systematic approach to debug conditional statements that aren't working as expected?

Check variable values, trace condition evaluation, verify operator precedence, check indentation, test edge cases, and use print statements to confirm values.

18
New cards

What are membership operators in Python?

in and not in, used to test whether a value exists in a list, string, or dictionary.

19
New cards

What are identity operators in Python?

is and is not, used to check whether two objects are the same type or reference.

20
New cards

What are nested if statements?

An if statement inside another if, creating multiple levels of decision-making.