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.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
- (A) is true and (R) is false.
- (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
Assertion (A): A Python dictionary is a collection of unordered data that stores values as key-value pairs.
Reason (R): In a dictionary, the keys are unique and serve as an index for accessing associated values.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
- (A) is true and (R) is false.
- (A) is false and (R) is true.
Assertion (A): Operators in Python are symbols that perform specific operations on operands.
Reason (R): Python provides various types of operators such as arithmetic, relational, and logical operators to perform different tasks in a program.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
- (A) is true and (R) is false.
- (A) is false and (R) is true.
Assertion (A): The for loop in Python is ideal when the number of iterations is known before the loop starts.
Reason (R): The for loop is particularly useful for iterating over collections such as lists, tuples, and dictionaries.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
- (A) is true and (R) is false.
- (A) is false and (R) is true.
Assertion (A): Functions defined in Python modules require importing the corresponding module before they can be used.
Reason (R): Modules like math and random define functions that can be accessed by importing them into the program.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
- (A) is true and (R) is false.
- (A) is false and (R) is true.