Any2Quiz
Quizzes / CBSE / Class 9 / Computer Science / Programming with Python

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, free

Sample questions

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

Take the full quiz

More questions in this quiz

Answers and explanations are in the full quiz.

  1. Which of the following is a looping structure in Python?
  2. What is the output of 'if 2 > 3: print('True') else: print('False')'?
  3. What does 'while True:' mean in a Python program?
  4. Which Python structure is used for decision making?
  5. What will be the output of the loop: 'for i in range(3): print(i)'?
  6. What happens if the condition in a Python 'while' loop is always False?
  7. What is the result of the expression: '10 > 5 and 5 < 3'?
  8. Which keyword is used to skip the current iteration in a loop?
  9. What is the elseif ladder used for?
  10. What happens if a loop contains a 'break' statement?
  11. What is the main advantage of using 'elif' instead of multiple 'if' statements?
  12. Which of the following best describes the 'pass' statement in a loop?
  13. What is the outcome of mixing tabs and spaces in Python indentation?
  14. What will be printed by 'for i in range(3): for j in range(2): print(i, j)'?
  15. Which of the following correctly demonstrates an 'else' being executed in a 'while' loop?

More quizzes

Browse all Programming with Python quizzes

More to play

Daily ChallengeA new quiz every day. Keep your streak.HangmanGuess the word, letter by letter.Story QuestLearn through short interactive stories.All quizzesCBSE, ICSE, competitive exams and more.