Control Structures (If-Else and Loops) Quiz - CBSE Class 9 Computer Science
Free practice quiz: Control Structures (If-Else and Loops) (CBSE Class 9 Computer Science). 20 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
This CBSE Class 9 Computer Science practice quiz has 20 multiple-choice questions on Control Structures (If-Else and Loops), and 20 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 20 questions, freeSample questions
What is the default else block in an if-else structure executed?
Show answer
Answer: B. When the if condition is false
The else block is executed only when the if condition evaluates to false.
What is the output when 'x = 5; if x == 5: print('Yes') else: print('No')' is executed?
Show answer
Answer: A. Yes
Since x equals 5, the if condition is true and 'Yes' is printed.
In an 'if' statement block in Python, what indicates that a block of code belongs to that statement?
Show answer
Answer: B. Indentation
Python uses indentation to define blocks of code, particularly for control structures like if statements.
What is the output of: 'for i in range(5, 1, -1): print(i)'?
Show answer
Answer: A. 5 4 3 2
The 'range(5, 1, -1)' generates numbers from 5 to 2 (step -1), printing 5, 4, 3, 2 on new lines.
In Python, what will happen if the indentation is incorrect in a loop?
Show answer
Answer: B. Syntax error
Indentation is crucial in Python since it defines the level of code hierarchy. Incorrect indentation will lead to a SyntaxError.
More questions in this quiz
Answers and explanations are in the full quiz.
- Which of the following is a looping structure in Python?
- What is the output of 'if 2 > 3: print('True') else: print('False')'?
- What does 'while True:' mean in a Python program?
- Which Python structure is used for decision making?
- What will be the output of the loop: 'for i in range(3): print(i)'?
- What happens if the condition in a Python 'while' loop is always False?
- What is the result of the expression: '10 > 5 and 5 < 3'?
- Which keyword is used to skip the current iteration in a loop?
- What is the elseif ladder used for?
- What happens if a loop contains a 'break' statement?
- What is the main advantage of using 'elif' instead of multiple 'if' statements?
- Which of the following best describes the 'pass' statement in a loop?
- What is the outcome of mixing tabs and spaces in Python indentation?
- What will be printed by 'for i in range(3): for j in range(2): print(i, j)'?
- Which of the following correctly demonstrates an 'else' being executed in a 'while' loop?
More quizzes
Browse all Programming with Python quizzes