KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Assertion (A): In Python, the if-else statement is used to execute one block of code when the condition is true, and another when it is false.

Reason (R): The if-else statement ensures that only one block of code is executed based on the given condition.

  1. Both (A) and (R) are true and (R) is a correct explanation of (A).
  2. Both (A) and (R) are true and (R) is not a correct explanation of (A).
  3. (A) is true and (R) is false.
  4. (A) is false and (R) is true.

Python Control Flow

1 Like

Answer

Both (A) and (R) are true and (R) is a correct explanation of (A).

Reason — The if-else statement in Python provides two alternative blocks of execution. When the given condition evaluates to True, the statements under the if block are executed, otherwise, the statements under the else block are executed. Thus, based on the condition, only one block of code is executed, which correctly explains the assertion.

Answered By

2 Likes


Related Questions