Getting Started with Python · Class 11 · CBSE · Science Computer Science
Explain the difference between a syntax error and a runtime error in Python, and give one example of each.
Practice question from Getting Started with Python (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.
medium · Subjective · Q-9E0268
Explain the difference between a syntax error and a runtime error in Python, and give one example of each.
Answer: A syntax error occurs when Python cannot understand the structure of a statement, such as in
if x > 5 print(x), because the colon is missing. A runtime error occurs while a syntactically valid program is running, such as print(10 / 0), which raises a ZeroDivisionError.Solution
A syntax error prevents Python from correctly parsing the program, whereas a runtime error occurs during execution after the program has been parsed successfully.
More from Getting Started with Python
- In Python's interactive mode, what does the prompt >>> generally indicate?
- What will be printed when the following Python code is executed and the user enters 12 on the first line and 3 on the second line? a = inpu…
- Which of the following is a valid Python identifier?
- What is the output of the following Python code? x = 7 y = 2 print(x // y, x % y)
Practise more Computer Science
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed