Conditional Statements Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
Which of these checks if a number is between 1 and 10 inclusive?
  • A if 1 <= num <= 10:
  • B if num >= 1 and num <= 10:
  • C if num in range(1, 11):
  • D All of the above
Answer: Option D
Explanation: The "and" operator can combine multiple conditions.
Q12
What will be the output of: x = 0; if x: print("Yes") else: print("No")
  • A Yes
  • B No
  • C Error
  • D 0
Answer: Option B
Explanation: In Python, 0 evaluates to False in boolean context.
Q13
Which operator has the highest precedence in conditional expressions?
  • A and
  • B or
  • C not
  • D ()
Answer: Option D
Explanation: Parentheses have the highest precedence and can be used to control evaluation order.
Q14
What is the purpose of nested if statements?
  • A To create loops
  • B To check conditions within other conditions
  • C To handle exceptions
  • D To define functions
Answer: Option B
Explanation: Nested if statements allow checking multiple conditions in a hierarchical manner.
Q15
What will be the output of: x = "hello"; if x: print("Yes") else: print("No")
  • A Yes
  • B No
  • C Error
  • D hello
Answer: Option A
Explanation: Non-empty strings are truthy in Python.
Q16
Which of these is NOT a valid way to check if a list is empty?
  • A if not my_list:
  • B if len(my_list) == 0:
  • C if my_list == []:
  • D if my_list == False:
Answer: Option D
Explanation: Comparing a list directly to False is not the correct way to check if it is empty.
Q17
What does the "pass" keyword do in an if statement?
  • A Skips to the next condition
  • B Does nothing, used as placeholder
  • C Terminates the program
  • D Continues to next iteration
Answer: Option B
Explanation: The pass statement is a null operation used as a placeholder.
Q18
What will be the output of: x = 10; if x > 5 and x < 15: print("In range")
  • A In range
  • B No output
  • C Error
  • D True
Answer: Option A
Explanation: Both conditions are True, so the message is printed.
Q19
Which of these is the correct syntax for if-elif-else?
  • A if-elseif-else
  • B if-else if-else
  • C if-elif-else
  • D if-elsif-else
Answer: Option C
Explanation: Python uses elif for else-if conditions, not elseif or else if.
Q20
What is short-circuit evaluation in conditional expressions?
  • A Using short variable names
  • B Evaluating only until result is determined
  • C Skipping else clauses
  • D Using ternary operators
Answer: Option B
Explanation: Short-circuit evaluation stops evaluating as soon as the result is determined.
Questions and Answers for Competitive Exams Various Entrance Test