πŸ”₯ LIVE πŸ‘©β€πŸ« Teachers: Host Live Tests  |  πŸŽ“ Students: Practice Class-wise Quizzes Go to Quiz Portal βž”

Computational Thinking and Programming-I Quiz 6

🐞 Computational Thinking & Programming-I Quiz 6 β€” Errors & Debugging (Class 11 CS)

Practice 20 CBSE Class 11 Computer Science (Code 083) MCQs on errors in programming β€” syntax errors, logical errors, run-time errors, common exception types (ZeroDivisionError, NameError, TypeError, ValueError, IndexError), and exception handling with try/except/finally.

Every error type below has been verified by actually triggering it in Python. Tap any question to reveal the answer with a clear explanation.

❌ Syntax Errors🧠 Logical ErrorsπŸ’₯ Runtime ErrorsπŸ” Error Detection🐞 DebuggingπŸ›Ÿ Exception Handling⚠️ Exception Types
Q1
❌ Syntax Errors

What are syntax errors in programming?

  1. Errors that occur during program execution
  2. Errors that cause logical inconsistencies
  3. Errors that violate the rules of the programming language
  4. Errors that result in incorrect program output
Show Answer & Explanation

βœ… Answer: (c) Errors that violate the rules of the programming language

Syntax errors happen when code breaks the grammar rules of the language β€” like a missing colon or an unclosed bracket. Python catches these before the program even starts running.

Q2
❌ Syntax Errors

Which of the following is a genuine example of a syntax error in Python?

  1. print(“Hello” (a missing closing parenthesis)
  2. 5 / 0
  3. Using a variable x before it is defined
  4. A while loop that never ends
Show Answer & Explanation

βœ… Answer: (a) print(“Hello” (a missing closing parenthesis)

A missing closing parenthesis breaks Python’s grammar rules and is caught immediately as a genuine SyntaxError β€” the program won’t even start. (Note: this question is corrected from a widely circulated version whose four options were actually all runtime or logical errors, with no true syntax error among them. Dividing by zero is a runtime ZeroDivisionError, an undefined variable raises a runtime NameError, and an infinite loop is a logical error.)

Q3
🧠 Logical Errors

What are logical errors in programming?

  1. Errors that occur during program execution
  2. Errors that cause the program to crash
  3. Errors that result in incorrect program output
  4. Errors that violate the rules of the programming language
Show Answer & Explanation

βœ… Answer: (c) Errors that result in incorrect program output

Logical errors don’t crash the program or trigger any error message β€” the code runs perfectly fine, but produces the wrong output because the underlying logic itself is flawed.

Q4
🧠 Logical Errors

Which of the following is an example of a logical error?

  1. Forgetting to close a file after reading from it
  2. Dividing a number by zero
  3. Using an incorrect algorithm
  4. Misspelling a variable name
Show Answer & Explanation

βœ… Answer: (c) Using an incorrect algorithm

Using an incorrect algorithm is a classic logical error β€” the program runs without crashing, but the wrong approach means it produces the wrong result. Dividing by zero causes a runtime error, and misspelling a variable name causes a NameError at runtime β€” neither is purely β€œlogical”.

Q5
πŸ’₯ Runtime Errors

What are run-time errors in programming?

  1. Errors that occur during program execution
  2. Errors that cause logical inconsistencies
  3. Errors that violate the rules of the programming language
  4. Errors that result in incorrect program output
Show Answer & Explanation

βœ… Answer: (a) Errors that occur during program execution

Run-time errors occur while the program is actually running β€” the syntax is valid and execution starts fine, but something goes wrong partway through (like dividing by zero), causing the program to crash.

Q6
πŸ’₯ Runtime Errors

Which of the following is an example of a run-time error?

  1. Syntax error in the program
  2. Infinite loop in the program
  3. Incorrect logic in the program
  4. Division by zero in the program
Show Answer & Explanation

βœ… Answer: (d) Division by zero in the program

Division by zero is a textbook run-time error β€” the code is syntactically correct and starts executing fine, but crashes with a ZeroDivisionError the moment that specific line runs.

Q7
πŸ” Error Detection

How are syntax errors detected in programming?

  1. By the programmer during program development
  2. By the computer at compile/translation time
  3. By the computer at run-time
  4. By running the program and analyzing the output
Show Answer & Explanation

βœ… Answer: (b) By the computer at compile/translation time

Syntax errors are caught by the computer during translation, before execution begins β€” Python parses the entire code first, and if the grammar is broken anywhere, it refuses to run the program at all.

Q8
πŸ” Error Detection

How are logical errors detected in programming?

  1. By the programmer during program development
  2. By the computer at compile time
  3. By the computer at run-time
  4. By running the program and analyzing the output
Show Answer & Explanation

βœ… Answer: (d) By running the program and analyzing the output

Logical errors are the trickiest to catch because the computer sees nothing wrong β€” no crash, no error message. They’re only found by running the program and checking whether the output actually matches what was expected.

Q9
πŸ” Error Detection

How are run-time errors detected in programming?

  1. By the programmer during program development
  2. By the computer at compile time
  3. By the computer at run-time
  4. By running the program and analyzing the output
Show Answer & Explanation

βœ… Answer: (c) By the computer at run-time

Run-time errors are detected by the computer while the program is actively executing β€” the interpreter halts and raises an exception the moment it hits the problematic line.

Q10
🐞 Debugging

Which type of error is generally the most challenging to debug and fix?

  1. Syntax errors
  2. Logical errors
  3. Run-time errors
  4. All types of errors pose similar challenges
Show Answer & Explanation

βœ… Answer: (b) Logical errors

Logical errors are the hardest to debug β€” the program runs without crashing and gives no error message at all, so you have to carefully trace through the logic yourself to figure out why the output is wrong.

Q11
πŸ›Ÿ Exception Handling

Which pair of Python keywords is used to catch and handle run-time errors gracefully instead of crashing?

  1. if / else
  2. try / except
  3. for / while
  4. def / return
Show Answer & Explanation

βœ… Answer: (b) try / except

try / except lets you β€œattempt” a block of risky code and catch any exception it raises, so the program can respond gracefully instead of crashing outright.

Q12
⚠️ Exception Types

Which error is raised when you try to access a list index that doesn’t exist?

  1. ValueError
  2. TypeError
  3. IndexError
  4. NameError
Show Answer & Explanation

βœ… Answer: (c) IndexError

Trying to access an out-of-range position, like L[10] on a 3-item list, raises an IndexError.

Q13
⚠️ Exception Types

Which error is raised when dividing a number by zero in Python?

  1. ZeroDivisionError
  2. ValueError
  3. TypeError
  4. OverflowError
Show Answer & Explanation

βœ… Answer: (a) ZeroDivisionError

Python raises a ZeroDivisionError specifically for this case β€” e.g. print(5/0) immediately crashes with this exception.

Q14
⚠️ Exception Types

Which error is raised when using a variable that hasn’t been defined yet?

  1. TypeError
  2. IndexError
  3. ValueError
  4. NameError
Show Answer & Explanation

βœ… Answer: (d) NameError

Referring to a variable that was never assigned a value raises a NameError, with a message like β€œname ‘x’ is not defined”.

Q15
⚠️ Exception Types

What error occurs when performing an operation on incompatible data types, such as “5” + 5?

  1. ValueError
  2. TypeError
  3. NameError
  4. IndexError
Show Answer & Explanation

βœ… Answer: (b) TypeError

Trying to add a string and an integer directly raises a TypeError β€” Python won’t silently guess how to combine incompatible types.

Q16
⚠️ Exception Types

Which error is raised when converting an invalid string to an integer, such as int(β€œabc”)?

  1. TypeError
  2. NameError
  3. ValueError
  4. IndexError
Show Answer & Explanation

βœ… Answer: (c) ValueError

Since β€œabc” isn’t a valid whole number, int("abc") raises a ValueError β€” the type of the argument is fine (it’s a string), but its content/value is not valid for the conversion.

Q17
πŸ›Ÿ Exception Handling

Which block in a Python try-except statement runs regardless of whether an exception occurred or not?

  1. try
  2. except
  3. finally
  4. else
Show Answer & Explanation

βœ… Answer: (c) finally

The finally block always executes β€” whether the try block succeeded, raised an exception, or the exception was caught β€” making it ideal for cleanup tasks like closing a file.

Q18
🐞 Debugging

What is a traceback in Python?

  1. A tool used to write code faster
  2. A report showing the sequence of function calls that led to an error
  3. A way to permanently fix logical errors
  4. A built-in Python data type
Show Answer & Explanation

βœ… Answer: (b) A report showing the sequence of function calls that led to an error

A traceback is the error report Python prints when an exception isn’t caught β€” it shows the chain of function calls (and line numbers) that led up to the error, which is invaluable for debugging.

Q19
🐞 Debugging

Which statement best distinguishes testing from debugging?

  1. Testing and debugging are the exact same process
  2. Testing finds errors in a program; debugging fixes them
  3. Testing fixes errors; debugging finds them
  4. Testing and debugging both only apply to syntax errors
Show Answer & Explanation

βœ… Answer: (b) Testing finds errors in a program; debugging fixes them

Testing is the process of running a program to discover whether errors exist (and where). Debugging is the separate, subsequent process of actually locating the root cause and fixing it.

Q20
❌ Syntax Errors

What term describes an error caused by breaking Python’s grammar rules, such as forgetting a colon after an if statement?

  1. Logical error
  2. Run-time error
  3. Syntax error
  4. Semantic error
Show Answer & Explanation

βœ… Answer: (c) Syntax error

Forgetting a required colon (:) after if, for, or def breaks Python’s required grammar, making it a syntax error β€” caught immediately, before the program can even begin running.

Jitendra Singh
βœ” Verified Educator

Jitendra Singh

Founder of CBSEPython.in

I help CBSE Class 9–12 students learn Python, Information Technology, Artificial Intelligence and Computer Science through easy notes, quizzes, MCQs and sample papers.

Read More About Me β†’