Questions: Comparison Operators and Boolean Tests

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer writes `if (x = 5) { doSomething(); }` intending to check whether x equals 5. In a language like C, what actually happens?

AThe condition checks whether x is equal to 5 and works as intended
Bx is assigned the value 5 and the condition evaluates to true (non-zero), so doSomething() always runs regardless of x's prior value
CA compile error occurs because = is not allowed inside a conditional
DThe program compares x to 5 but also stores 5 in x as a side effect
Question 2 Multiple Choice

What does Python return for the expression `'Banana' < 'apple'`?

AFalse — 'banana' comes after 'apple' alphabetically, so 'Banana' must be greater
BFalse — Python compares string lengths when letter comparisons are ambiguous
CTrue — uppercase letters have lower Unicode values than lowercase letters, so 'B' < 'a'
DAn error — Python cannot compare strings with mixed case using <
Question 3 True / False

In Python, `'Banana' < 'apple'` evaluates to True, even though 'banana' comes after 'apple' in the dictionary.

TTrue
FFalse
Question 4 True / False

The single equals sign (=) and the double equals sign (==) can be used interchangeably in conditional expressions in most programming languages.

TTrue
FFalse
Question 5 Short Answer

Why do comparison operators return a boolean value, and how does this connect them to conditional statements like `if`?

Think about your answer, then reveal below.