Exercises · Q8
Q.Categorise the following as syntax error, logical error or runtime error:
a) 25 / 0
b) num1 = 25; num2 = 0; num1/num2
Yanam CbseNCERTSubjective· 2mImportance★★★★★est
71% · 35/49 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Both (a) and (b) are runtime errors — each is grammatically correct Python that crashes with ZeroDivisionError the moment the division is executed.
Recall the three categories:
- Syntax error — the code violates Python's grammar, so it never starts running (e.g. a missing colon).
- Logical error — the code runs to completion but produces a wrong result because the logic is flawed (e.g. using
+where-was intended). - Runtime error — the code is grammatically valid and starts executing, but an operation becomes impossible while it runs, raising an exception.
a) 25 / 0 — the expression parses fine; the interpreter only discovers the impossible operation when it evaluates the division:
>>> 25 / 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
This is a runtime error.
b) num1 = 25; num2 = 0; num1/num2 — the first two assignments execute normally; the third statement then divides by the value of num2, which happens to be 0:
>>> num1 = 25; num2 = 0; num1/num2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
``` …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.