π 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
What are syntax errors in programming?
- Errors that occur during program execution
- Errors that cause logical inconsistencies
- Errors that violate the rules of the programming language
- 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.
β Syntax Errors
Which of the following is a genuine example of a syntax error in Python?
- print(“Hello” (a missing closing parenthesis)
- 5 / 0
- Using a variable x before it is defined
- 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.)
π§ Logical Errors
What are logical errors in programming?
- Errors that occur during program execution
- Errors that cause the program to crash
- Errors that result in incorrect program output
- 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.
π§ Logical Errors
Which of the following is an example of a logical error?
- Forgetting to close a file after reading from it
- Dividing a number by zero
- Using an incorrect algorithm
- 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β.
π₯ Runtime Errors
What are run-time errors in programming?
- Errors that occur during program execution
- Errors that cause logical inconsistencies
- Errors that violate the rules of the programming language
- 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.
π₯ Runtime Errors
Which of the following is an example of a run-time error?
- Syntax error in the program
- Infinite loop in the program
- Incorrect logic in the program
- 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.
π Error Detection
How are syntax errors detected in programming?
- By the programmer during program development
- By the computer at compile/translation time
- By the computer at run-time
- 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.
π Error Detection
How are logical errors detected in programming?
- By the programmer during program development
- By the computer at compile time
- By the computer at run-time
- 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.
π Error Detection
How are run-time errors detected in programming?
- By the programmer during program development
- By the computer at compile time
- By the computer at run-time
- 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.
π Debugging
Which type of error is generally the most challenging to debug and fix?
- Syntax errors
- Logical errors
- Run-time errors
- 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.
π Exception Handling
Which pair of Python keywords is used to catch and handle run-time errors gracefully instead of crashing?
- if / else
- try / except
- for / while
- 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.
β οΈ Exception Types
Which error is raised when you try to access a list index that doesn’t exist?
- ValueError
- TypeError
- IndexError
- 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.
β οΈ Exception Types
Which error is raised when dividing a number by zero in Python?
- ZeroDivisionError
- ValueError
- TypeError
- 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.
β οΈ Exception Types
Which error is raised when using a variable that hasn’t been defined yet?
- TypeError
- IndexError
- ValueError
- 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β.
β οΈ Exception Types
What error occurs when performing an operation on incompatible data types, such as “5” + 5?
- ValueError
- TypeError
- NameError
- 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.
β οΈ Exception Types
Which error is raised when converting an invalid string to an integer, such as int(βabcβ)?
- TypeError
- NameError
- ValueError
- 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.
π Exception Handling
Which block in a Python try-except statement runs regardless of whether an exception occurred or not?
- try
- except
- finally
- 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.
π Debugging
What is a traceback in Python?
- A tool used to write code faster
- A report showing the sequence of function calls that led to an error
- A way to permanently fix logical errors
- 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.
π Debugging
Which statement best distinguishes testing from debugging?
- Testing and debugging are the exact same process
- Testing finds errors in a program; debugging fixes them
- Testing fixes errors; debugging finds them
- 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.
β Syntax Errors
What term describes an error caused by breaking Python’s grammar rules, such as forgetting a colon after an if statement?
- Logical error
- Run-time error
- Syntax error
- 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.
