Conditional Statements Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q1
Which keyword is used to start an if statement in Python?
  • A when
  • B if
  • C else
  • D condition
Answer: Option B
Explanation: The "if" keyword is used to start conditional statements in Python.
Q2
What is the correct syntax for an if statement in Python?
  • A if (x > y) { }
  • B if x > y then
  • C if x > y:
  • D if x > y then:
Answer: Option C
Explanation: In Python, if statements end with a colon and the code block is indented.
Q3
Which keyword is used for alternative conditions in an if statement?
  • A elseif
  • B else if
  • C elif
  • D otherwise
Answer: Option C
Explanation: The "elif" keyword is used for else-if conditions in Python.
Q4
What will be the output of: x = 5; if x > 3: print("Hello")
  • A Hello
  • B No output
  • C Error
  • D True
Answer: Option A
Explanation: Since x=5 is greater than 3, the condition evaluates to True and "Hello" is printed.
Q5
Which operator is used for logical AND in Python?
  • A &&
  • B AND
  • C and
  • D &
Answer: Option C
Explanation: The "and" operator is used for logical AND operations in Python.
Q6
What is the purpose of the else clause in an if statement?
  • A To handle errors
  • B To execute when if condition is True
  • C To execute when all conditions are False
  • D To create a loop
Answer: Option C
Explanation: The else clause executes when all previous conditions are False.
Q7
Which of these is a valid conditional expression?
  • A if x = 5:
  • B if x == 5:
  • C if x equals 5:
  • D if x === 5:
Answer: Option B
Explanation: Conditional expressions should use proper Python syntax with comparison operators.
Q8
What will be the output of: x = 2; if x > 5: print("A") elif x > 1: print("B") else: print("C")
  • A A
  • B B
  • C C
  • D No output
Answer: Option B
Explanation: x=2 is not greater than 5, but it is greater than 1, so "B" is printed.
Q9
Which operator is used for logical OR in Python?
  • A ||
  • B OR
  • C or
  • D |
Answer: Option C
Explanation: The "or" operator is used for logical OR operations in Python.
Q10
What is the result of: if not False: print("True")
  • A True
  • B False
  • C Error
  • D No output
Answer: Option A
Explanation: not False evaluates to True, so the print statement executes.
Questions and Answers for Competitive Exams Various Entrance Test